采用PEAR来缓冲PHP程序二_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了采用PEAR来缓冲PHP程序二_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2115字,纯文字阅读大概需要4分钟。
内容图文
![采用PEAR来缓冲PHP程序二_PHP教程](/upload/InfoBanner/zyjiaocheng/177/3bbb199f4f1944cda94ebbc0195ff149.jpg)
最后,我们来定制一个应用,综合的来解释 PEAR 缓冲机制的整体框架。 我们定义一个叫做 MySQL_Query_Cache 的类,缓冲 SELECT 的查询结果。 我们首先定义类的变量: ’.’, ’filename_prefix’ => ’cache_’), $expires = 3600) { $this->Cache($container, $container_options); $this->expires = $expires; } 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) or trigger_error(’数据库连接失败!’, E_USER_ERROR); mysql_select_db($database, $this->connection) or trigger_error(’数据库选择失败!’, E_USER_ERROR); } function fetch_row() { if ($this->cursor < sizeof($this->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); // 把结果缓冲 $this->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’); while ($row = $cache->fetch_row()) { echo ’
’; print_r($row); echo ’
’; } ?> <全文完>
http://www.bkjia.com/PHPjc/531729.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/531729.htmlTechArticle最后,我们来定制一个应用,综合的来解释 PEAR 缓冲机制的整体框架。 我们定义一个叫做 MySQL_Query_Cache 的类,缓冲 SELECT 的查询结果。 我...
全文完>
内容总结
以上是互联网集市为您收集整理的采用PEAR来缓冲PHP程序二_PHP教程全部内容,希望文章能够帮你解决采用PEAR来缓冲PHP程序二_PHP教程所遇到的程序开发问题。
如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
来源:【匿名】