mysql_free_result(): 2 is not a valid MySQL result resource
为啥???
下面是源码....救救我
public function query($str){
if ($this -> Num > 10){
mysql_free_result($this -> result) or die('释放不成功>>');
echo '有数据缓存::'.$this -> Num;
}else{
$this -> result = mysql_query($str);
echo $this -> Num = mysql_num_rows($this -> result);
}
}
有两个资源吗?但是我close也消除不了,用的是单例
为啥???
下面是源码....救救我
public function query($str){
if ($this -> Num > 10){
mysql_free_result($this -> result) or die('释放不成功>>');
echo '有数据缓存::'.$this -> Num;
}else{
$this -> result = mysql_query($str);
echo $this -> Num = mysql_num_rows($this -> result);
}
}
有两个资源吗?但是我close也消除不了,用的是单例
echo mysql_free_result($this -> result) ? '释放成功>>>' : die('数据库资源未被释放');
$this -> result = null;
}
public function query($str){
if ($this -> Num > 10){//设置查询资源条目上限,超过上限则释放资源
$this -> free();
echo '有数据缓存::'.$this -> Num.'<br/>';
}
$this -> result = mysql_query($str);
echo $this -> Num = mysql_num_rows($this -> result);
echo '<br/>';
}
<?php
final class dbdrv extends db{
protected function dbdrv(){
//construct of the db class
//why ? not new the dbdrv class
$this -> conn('localhost','root',123);
$this -> dbs('test');
$this -> set('GBK');
}
private function conn($H,$U,$P){
//Connect the DataBase
mysql_connect($H,$U,$P);
}
public function dbs($db){
//select the DataBase Name
mysql_select_db($db);
}
public function set($set){
mysql_query("SET NAMES $set");
}
public function free(){
echo mysql_free_result($this -> result) ? '释放成功>>>' : die('数据库资源未被释放');
$this -> result = null;
}
public function query($str){
if ($this -> Num > 10){
$this -> free();
echo '有数据缓存::'.$this -> Num.'<br/>';
}
$this -> result = mysql_query($str);
echo $this -> Num = mysql_num_rows($this -> result);
echo '<br/>';
}
}
class db{
public $Num;
public $result;
private static $instance = null;
//the instance the dbdrv class for singleton
private function dbdrv(){//null
}
public function inc(){
if ( null == self::$instance ) self::$instance = new dbdrv();
return self::$instance;
}
public function num(){
echo '缓存的数据::'.self::$instance -> Num;
}
}
//test
db::inc() -> query('SELECT * FROM db');
db::inc() -> query('select * from hh');
db::inc() -> query('select * from hh');
echo '<hr>';
// $d = new db();
//$d -> num();
?>