警告:mysqli_error()恰好需要1个参数,给定0个参数?

时间:2019-04-23 23:11:28

标签: php function mysqli

我下载了此Internet脚本,并对其进行了更改以匹配我的项目,但不再起作用。我已经比较了自己的作品和原始作品,无法找出问题所在。

以下是我遇到的功能

private function getData($sqlQuery) { //creates a function named 'getData' with a required parameter
  $result = mysqli_query($this->dbConnect, $sqlQuery);  //uses mysqli to query against the "$dbConnect" resource using the passed parameter $sqlQuery
  if(!$result){ //If the result doesn't exist die
    die('Error in query: '. mysqli_error()); //die and show error
  }//peforms a  query against database to check it is connected
  $data= array();  //create an empty array
  while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { //fetch a row using association (aka an array mapped by keys with no numbered index)
    $data[]=$row; //array push the returned row
  }
  return $data; //return an array of arrays from MySql
}

这是以前工作过的原始

private function getData($sqlQuery) {
        $result = mysqli_query($this->dbConnect, $sqlQuery);
        if(!$result){
            die('Error in query: '. mysqli_error());
        }
        $data= array();
        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
            $data[]=$row;
        }
        return $data;
    }

我的课程评分

class Rating{
    private $host  = 'localhost';
    private $user  = 'root';
    private $password   = "";
    private $database  = "phplogin";
    private $customerTable = 'accounts';
    private $staffTable = 'users';
    private $staffRatingTable = 'staff_rating';
    private $dbConnect = false;
    public function __construct(){
        if(!$this->dbConnect){
            $conn = new mysqli($this->host, $this->user, $this->password, $this->database);
            if($conn->connect_error){
                die("Error failed to connect to MySQL: " . $conn->connect_error);
            }else{
                $this->dbConnect = $conn;
            }
        }
    }

原始课程评分

class Rating{
    private $host  = 'localhost';
    private $user  = 'root';
    private $password   = "";
    private $database  = "test";
    private $itemUsersTable = 'item_users';
    private $itemTable = 'item';
    private $itemRatingTable = 'item_rating';
    private $dbConnect = false;
    public function __construct(){
        if(!$this->dbConnect){
            $conn = new mysqli($this->host, $this->user, $this->password, $this->database);
            if($conn->connect_error){
                die("Error failed to connect to MySQL: " . $conn->connect_error);
            }else{
                $this->dbConnect = $conn;
            }
        }
    }

0 个答案:

没有答案