警告:mysqli_query()期望参数1为mysqli,给定的整数

时间:2015-10-14 14:16:44

标签: php mysqli

有很多相关问题的帖子,但问题仍然存在,对不起,请帮我解决这个问题。

    <?php

$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbase="cms";

$connection=mysqli_connect("$dbhost","$dbuser","$dbpass","$dbase");
if($connection=mysqli_connect_errno()){
    echo "Error estabilishing conection : ".mysqli_connect_error(). "(" .mysqli_connect_errno().")";
}

?>


<?php 

$query = "SELECT * FROM pages";
$result = mysqli_query($connection, $query);
if(!$result){
    die("Database query failed..");
}

?>

1 个答案:

答案 0 :(得分:3)

if($connection=mysqli_connect_errno()){

mysqli_connect_errno()分配给$connection变量。

此行应替换为:

if (!$connection) {

完整的连接代码是:

$connection=mysqli_connect("$dbhost","$dbuser","$dbpass","$dbase");
if(!$connection){
    echo "Error estabilishing conection : ".mysqli_connect_error(). "(" .mysqli_connect_errno().")";
}