mysqli_select_db()期望参数1是mysqli,给出的string

可能重复:
mysql_fetch_array()期望参数1是资源,布尔在select中给出

我是Mysqli_ *的新手,我收到这些错误:

警告:mysqli_select_db()期望参数1是mysqli,在第11行D:\ Hosting \ 9864230 \ html \ includes \ connection.php中给出的string

警告:mysqli_error()需要在第13行D:\ Hosting \ 9864230 \ html \ includes \ connection.php中给出的只有1个参数

数据库select失败:

<?php require("constants.php"); // 1. Create a database connection $connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS); if (!$connection) { die("Database connection failed: " . mysqli_error()); } // 2. Select a database to use $db_select = mysqli_select_db(DB_NAME,$connection); if (!$db_select) { die("Database selection failed: " . mysqli_error()); } ?> 

你的论点是错误的。 根据文档 ,连接是第一位的

 <?php require("constants.php"); // 1. Create a database connection $connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS); if (!$connection) { die("Database connection failed: " . mysqli_error()); } // 2. Select a database to use $db_select = mysqli_select_db($connection, DB_NAME); if (!$db_select) { die("Database selection failed: " . mysqli_error()); } ?> 
 // 2. Select a database to use $db_select = mysqli_select_db($connection, DB_NAME); if (!$db_select) { die("Database selection failed: " . mysqli_error($connection)); } 

你得到了mysqli_select_db()的参数顺序。 而mysqli_error()要求你提供一个连接参数。 mysqli_XXX不像mysql_XXX,这些参数不再是可选的。

还要注意,用mysqli你可以在mysqli_connect()指定数据库:

 $connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME); if (!$connection) { die("Database connection failed: " . mysqli_connect_error(); } 

必须使用mysqli_connect_error()而不是mysqli_error()来从mysqli_connect()获取错误,因为后者要求您提供有效的连接。