Warning: mysqli_query() expects parameter 1 to be

2019-03-04 15:36发布

问题:

include_once("php/db_connects.php");

$tbl_status = "CREATE TABLE IF NOT EXISTS status ( 
                id INT(11) NOT NULL AUTO_INCREMENT,
                osid INT(11) NOT NULL,
                account_name VARCHAR(16) NOT NULL,
                author VARCHAR(16) NOT NULL,
                type ENUM('a','b','c') NOT NULL,
                data TEXT NOT NULL,
                postdate DATETIME NOT NULL,
                PRIMARY KEY (id) 
                )"; 
$query = mysqli_query($tbl_status, $db_connects); 
if ($query === TRUE) {
    echo "<h3>status table created </h3>"; 
} else {
    echo "<h3>status table NOT created </h3>"; 
}

I keep getting the mysqli error. Im prtty sure that i'm not using msql in my php.

回答1:

change this

$query = mysqli_query($tbl_status, $db_connects); 

to

$query = mysqli_query($db_connects, $tbl_status); 

example mysqli_query( mysqli $link , string $query )



回答2:

The signature for mysqli_query is:

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

Assuming $db_connects is the variable storing the result of mysqli_connect, you need to flip your arguments to fit:

mysqli_query($db_connects, $tbl_status); 

mysqli_query documentation



标签: php mysql mysqli