错误mysqli_query()需要至少2个参数

时间:2019-06-21 15:31:20

标签: php mysqli

我无法将代码从mysql更新为mysqli

执行此php时出现以下错误:

PHP Warning: mysqli_query() expects at least 2 parameters, 1 given in /var/www/html/form/ajax/count.php on line 7

我不认为这段代码会发生什么以及需要分配什么参数。 有人可以帮忙吗?

count.php 代码为:

$query = "SELECT count(*) AS total FROM users;";

    if (!$result = mysqli_query($query)) {
        exit(mysqli_error());
    }

    while($row = mysqli_fetch_assoc($result))
    {
        echo $row['total']." Register";        
    }

db_connection.php 代码为:

$user = "root";
$password = "123456";
$database = "clients";

$db = mysqli_connect($host, $user, $password, $database) or die("Could not connect to database");
  if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_close($db);```

0 个答案:

没有答案