ホームページ  >  記事  >  バックエンド開発  >  PEAR を使用した PHP プログラムのバッファー 2_PHP チュートリアル

PEAR を使用した PHP プログラムのバッファー 2_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:29:04957ブラウズ

最後に、アプリケーションをカスタマイズして、PEAR バッファリング メカニズムの全体的なフレームワークを包括的に説明しましょう。 SELECT クエリの結果をキャッシュするために、MySQL_Query_Cache というクラスを定義します。 まずクラスの変数を定義します: '.', 'filename_prefix' => 'cache_'), $expires = 3600) { $this->Cache($container, $container_options);有効期限が切れます; } function _MySQL_Query_Cache() { if (is_resource($this->connection)) { mysql_close($this->connection) } $this->_Cache() } ?> 始める前に、いくつかの補助機能が必要です。機能 。 function connect($hostname, $username, $password, $database) { $this->connection = mysql_connect($hostname, $username, $password) またはtrigger_error('データベース接続に失敗しました!', mysql_select_db($database); , $this->connection) またはtrigger_error('データベースの選択に失敗しました!', E_USER_ERROR); } function fetch_row() { if ($this->cursor result)) { return $this->result[$this->cursor++ ]; } else { return false; } } function num_rows() { return sizeof($this->result); } ?> バッファリングの方法を見てみましょう: result = $this->get($cache_id, 'mysql_query_cache' ) ; if ($this->result == NULL) { // バッファ損失 $this->cursor = 0; $this->result = array(); if (is_resource($this->connection)) { // mysql_unbuffered_query() 可能な場合 if (function_exists('mysql_unbuffered_query')) {$result = mysql_unbuffered_query($query, $this->connection) } else {$result = mysql_query($query, $this->connection); / すべてのクエリ結果を取得します while ($row = mysql_fetch_assoc($result)) {$this->result[] = $row } // MySQL 結果リソースを解放します mysql_free_result($result); // 結果をバッファします。 >save($cache_id, $this->result, $this->expires, 'mysql_query_cache'); } } } else { // クエリ結果はなく、バッファリングも必要ありません return mysql_query($query, $this->connection); } } ?> 例 3: MySQL クエリ キャッシュを使用する connect('hostname', 'username', 'password', 'database'); $cache->query('select * from table'); $cache->fetch_row()) { echo '

'; echo '
';
http://www.bkjia.com/PHPjc/531729.html

www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/531729.html技術記事最後に、アプリケーションをカスタマイズして、PEAR バッファリング メカニズムの全体的なフレームワークを包括的に説明しましょう。 SELECT クエリの結果をキャッシュするために、MySQL_Query_Cache というクラスを定義します。 私は...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。