2013-03-10 57 views
2
Warning: mysql_query() expects parameter 2 to be resource, string given 
in /var/www/xxxxx/data/www/xxxxx.ru/xxxxx/classes/mysql.class.php on line 51 
public function query($query, $comment = "") { 
    if ($this -> conn) { 
     $this -> conn = $this -> connect(); 
    } 
    $start = microtime(); 
    if (!($result = mysql_query($query, $this -> conn))) // <<-- line 51 
    { 
     exit(mysql_error()); 
    } 
    $end*emphasized text* = microtime(); 

這裏有什麼問題?警告:請求mysql_query()預計參數2是資源,串在/ var/WWW給出/

+1

不應該是'if(!$ this - > conn){'(!)? – dfsq 2013-03-10 08:44:03

回答

1

$conn很可能不會被初始化。

確保您在構造函數中將$ conn設置爲NULL,並根據if(!$this->conn)(請注意感嘆號)進行檢查,或者在構造函數中進行連接。

有了這樣的錯誤消息,請考慮使用var_dump來檢查有問題的變量的內容。

此外,只是爲了完整:mysql函數被mysqli函數取代。請考慮使用這些。

0

您這裏有一個錯誤:

if ($this->conn) { 
    $this->conn = $this -> connect(); 
} 

應該if (!$this->conn) {。否則$this->conn永遠不會初始化,並且您沒有通過後續的mysql_query

我相信你宣佈它作爲你的類空字符串:public $conn = '';

順便說一句,大家都知道,mysql擴展已被棄用,對不對?

+0

如將正確 – evanto 2013-03-10 08:52:12

+0

[鏈接](http://studio35.ru/mysql.class.zip)我想如果我告訴你,整個文件將更清楚可能是一個錯誤 – evanto 2013-03-10 09:07:14

相關問題