mysqli_select_db()期望参数1为mysqli,给定字符串
我是Mysqli_ *的新手,并且出现以下错误:
警告:mysqli_select_db()期望参数1为mysqli,第11行的D:\ Hosting \ 9864230 \ html \
includes \ connection.php中给出的字符串
警告:mysqli_error()恰好需要1个参数,第13行的D:\ Hosting \ 9864230 \ html \ includes \
connection.php中给出的参数为0
数据库选择失败:
<?phprequire("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());
}
?>
回答:
您的论点顺序错误。根据文档,连接优先
<?phprequire("constants.php");
// 1. Create a database connection
$connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
error_log("Failed to connect to MySQL: " . mysqli_error($connection));
die('Internal server error');
}
// 2. Select a database to use
$db_select = mysqli_select_db($connection, DB_NAME);
if (!$db_select) {
error_log("Database selection failed: " . mysqli_error($connection));
die('Internal server error');
}
?>
以上是 mysqli_select_db()期望参数1为mysqli,给定字符串 的全部内容, 来源链接: utcz.com/qa/417868.html