Login   Register  
PHP Classes
elePHPant
Icontem

File: example_2_SQL.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jacek Wloka  >  cache_TS  >  example_2_SQL.php  >  Download  
File: example_2_SQL.php
Role: Example script
Content type: text/plain
Description: example 2 sql
Class: cache_TS
Cache the output of PHP script in files
Author: By
Last change: the catalogue cache has to have chmod 666 or 777
Date: 2007-08-23 06:00
Size: 1,986 bytes
 

Contents

Class file image Download
<?php

/* the catalogue cache has to have chmod 666 or 777 */

/*========================*\

 * cache_TS
 * Written by: AS
 * Mialto: as@twoja-strona.net
 * Date: 2007-08-23
 * Cache: multiSystem cache SQL and PHP code
 * Version: 1 
 * Licencia: Lesser General Public License (LGPL)   
 * 
 * Copyright (C) 2007 Jacek Wloka
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.  

\*========================*/

function getmicrotime(){ 
    list(
$usec$sec) = explode(" ",microtime()); 
    return ((float)
$usec + (float)$sec); 
}

$host_sql 'localhost'/* host */
$user_sql 'root'/* user */
$pass_sql 'krasnal'/* password */
$db_sql 'database1'/* database */

$connect_sql = @mysql_connect($host_sql$user_sql$pass_sql);
if (!
$connect_sql) {exit('the lack of the connection...');}
if (!
mysql_select_db($db_sql)) {exit('the lack of the database...');}

include (
'cache_ts.php');

$cache = &new cache_TS();

// the question sql
$q 'SELECT * FROM `test`';

$time_start getmicrotime(); 

/******************************************************************************\

  check_cache('sql $q', second=300, dir='./cache')

\******************************************************************************/

if ($cache->check_cache($q300))
{
    
$cache->start_cache();

    
$q_sql mysql_query($q);
    while (
$row mysql_fetch_array($q_sql))
    {
           echo 
'<hr /><br />';
           
printf ("ID: %s  Data: %s"$row[ID], $row[TEXT]);
    }

    
$cache->end_cache();
}
 else
{
    
$cache->contents_cache();


mysql_close($connect_sql);

$time_end getmicrotime(); 
$time $time_end $time_start
echo 
'<hr /><br />Generate in '.$time.' s. <a href="?">refresh</a>'

?>