<?php class Cache { private $buffer; private $mode; private $file; private $handle; private $line = 0; public function cache_start ($handle = 0, $type) { $this -> handle = $handle; $this -> mode = 1; } else { $this -> mode = 2; } } else $this -> mode = 0; } public function cache_get () { if ($this -> mode == 1){ return false; else { return $this -> buffer [$this -> line]; $this -> line++; } }else return false; } public function cache_set ($value) { if ($value) { if ($this -> mode == 2) { $this -> buffer[] = $value; } return $value; } } public function cache_mode () { return $this -> mode; } public function cache_end () { if($this -> mode == 2) $this -> mode = 0; $this -> line = 0; } } ?>
I testuje ja na zalążku sterownika bazy danych :
<?php private $handle; private $sql_query; private $cache; private $rows; function __construct ($host, $login, $password, $db) { $this -> cache = new Cache; } function &connect ($host = false, $login = false, $password = false, $db = false) { if ($instance == false) return $instance; } function query ($sql, $handle = 0) { $this -> cache -> cache_start ($handle, "sql"); if ($this -> cache -> cache_mode() !== 1) { } } return true; } function num_rows () { } function real_escape_string ($str) { } function fetch_array () { if ($this -> cache -> cache_mode() == 1) { return $this -> cache -> cache_get(); }else { } } function free_result () { $this -> cache -> cache_end (); } function close () { } } ?>
Tak więc testuje:
TEST.php
<?php $db -> query ("SELECT * FROM users", "userzy"); while ($row =$db -> fetch_array ()) { } $db -> free_result (); ?>
Gdy plik nieistnieje i wywoływana jest funkcja cache_set wszystko działa, ale jeżeli już dane pobierane są za pomocą cache_get już nie :/ (nieskończona pętla)
Jakieś pomysły

