将mysql转换为mysqli错误

时间:2018-07-19 11:33:13

标签: mysql mysqli

我正在尝试将mysql转换为mysqli,但是出现一些错误

第一个错误: mysqli_query()至少需要2个参数,第55行的/home/.........../class/class.mysql.php中给出1个参数

public function query($res, $pass_no = 1) {
    $q1 = mysqli_query($res, $this->db_link);
    if (!$q1) {
        $this->sql_error();
        if ($pass_no == 1) {
            if ($this->output_error == 1) {
                echo 'Attempting to reconnect to MySQL...' . "\n";
            }
            $this->db_close();
            $this->db_connect();
            $this->query($res, 2);
        } else {
            if ($this->output_error == 1) {
                echo 'Reconnection failed; please check your MySQL server settings!' . "\n";
            }
        }
    } else {
        return $q1;
    }
}

第二个错误: mysqli_real_escape_string()恰好需要2个参数,第14行的/home/..../index.php中给出了1个参数

global  $db ;

$username = mysqli_real_escape_string($_POST['username_login']);

      $q ="select * from ".DB_PREFIX."admins where username='".$username."' ".
        "and password='".md5( $_POST['password_login'])."'";
   // echo $q;
    $res =$db->query($q);
    if($db->num_rows($res)==1)
    {

        return true ;
    }

return false ;

我不明白这两个错误

1 个答案:

答案 0 :(得分:0)

遇到错误时:请reading the manual来帮助自己。

1)

  

第一个错误:mysqli_query()至少需要2个参数,第55行的/home/.........../class/class.mysql.php中给出1个参数

您的代码:

$q1 = mysqli_query($res, $this->db_link);

应为:

$q1 = mysqli_query($this->db_link, $res);

具有数据库连接变量 FIRST 几乎所有mysqli_函数的必需变量。

2)

  

第二个错误:mysqli_real_escape_string()恰好需要2个参数,第14行的/home/..../index.php中给出了1个参数

请参阅上面的第1点:

mysqli_real_escape_string($connectionVariable, $_POST['username_login']);

3)

$q ="select * from ".DB_PREFIX."admins where username='".$username."' ".
    "and password='".md5( $_POST['password_login'])."'";

不要这样做!!!密码应使用PHP的专家password_hash函数进行存储。如果您需要在旧版本的PHP上使用它,请阅读how to use itwhy you should use itwhy it should be usedthe benefits of using ithere