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();
这里有什么问题吗?
最佳答案
$conn
很可能不会被初始化。
确保您在构造函数中将 $conn 设置为 NULL
并检查 if(!$this->conn)
(注意感叹号)或者在构造函数中进行连接。
对于这样的错误消息,请考虑使用 var_dump
检查相关变量的内容。
另外,为了完整起见:mysql
函数被 mysqli
函数取代。请考虑改用它们。
关于mysql -/var/www/中给出的警告 : mysql_query() expects parameter 2 to be resource, 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15320457/