mysql -/var/www/中给出的警告 : mysql_query() expects parameter 2 to be resource, 字符串

标签 mysql class warnings

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/

相关文章:

java - XAMPP Mysql packet too big异常如何解决

mysql - 选择大于平均值的值

javascript - D3v4图类,添加节点时遇到问题

c++ - GCC 编译器警告溢出

php - 通过 MySql 数据库创建动态内容?

python django 名称约定

java - 构建我自己的类?

python -We ResourceWarning 没有错误

azure - 如果有警告,则使构建失败,YAML

php - MySQL 查询获取数组不起作用