2013-03-10 56 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

相关问题