データベース結果セットのリリースに関する問題

WBOY
リリース: 2016-06-13 13:35:40
オリジナル
1090 人が閲覧しました

データベースの結果セットの公開の問題について。
class DB{
private $host; //サービスエリアアドレス
private $user; //ログインアカウント
private $name;名前
private $font; //データベース文字セット
private $conn; //結果セット
private $rowRst; > private $rowArray=array(); //複数のレコードをクエリします
private $rowAff //追加、変更、または削除されたレコードの数

public function __construct($host,$user,$pass, $name,$font){
$this->gt;host=$host;
$this->gt;user=$user;
$this->gt;pass=$pass;
$ this->name=$name;
$this->font=$font;
$this->init_conn();
}

//データベースに接続
プライベート関数 init_conn(){
if(!$this->conn=mysql_connect($this->host,$this->user,$this->pass)){
exit ( 'データベース接続エラー');
}
if(!mysql_select_db($this->name,$this->conn)){
exit('データベース選択エラー');
}
if(!mysql_query('SET NAMES '.$this->font)){
exit('文字セットエラー');
}
}

/ / SQL ステートメントを実行
public function _query($sql){
if(!$this->result=mysql_query($sql,$this->conn)){
exit('sql実行失敗');
}
return $this->result;
}

//ヘッドアップ データのクエリ
public function _fetch_array($sql){
$this->query($sql);
$this->rowRst=mysql_fetch_array($this->result,MYSQL_ASSOC);
return $this->rowRst;
}

//複数のデータをクエリします
public function _fetch_array_list($sql){
$this->_query($sql);
while (!!$rows=mysql_fetch_array($ this-> ;result,MYSQL_ASSOC)){
$this->rowArray[]=$rows;
}
return $this->rowArray;
}

//変更と削除の影響を受けるレコードの数を追加します
public function _affected_rows(){
$this->gt;rowAff=mysql_affected_rows();
return $this->gt;rowAff;
}

//前の INSERT オペレーションの ID 番号を取得します
public function _insert_id(){
return mysql_insert_id();
}

// 結果セットを解放します
public function _free_result( ){
$this->rowAff='';
$this->rowArray='';
$this->rowRst='';
mysql_free_result($this->free_result();
}

//データベースを閉じる
public function _close_conn(){
$this->free_result();
mysql_close ($this->conn );
}
}
_close_conn メソッドを使用すると、Web ページに mysql_free_result() が表示されます: 指定された引数は有効な mysql 結果リソースではありません
解決方法この問題



-----解決策---------

mysql_free_result($this->result); の前に、$this->result がどのようになるかを見てみましょう。それは最初に開いたリソースですか? ------解決策---------

if(is_resource($this->result ) ){ mysql_free_result($this->result);
$this->result = NULL;
}

------解決策----------------------

$this->結果は次のようになります。 $this->result=mysql_query($sql,$this->conn)
mysql_query は select ステートメントの実行時にリソースのみを返し、その他は論理値です

したがって、mysql_free_result($this->result);
と記述する必要があります
if(is_resource($this->result)) mysql_free_result($this->result);


関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!