我正在编写一个简单的数据库来练习,但我一直收到这个错误:
致命错误:在布尔值中调用成员函数query() 第43行/Applications/XAMPP/xamppfiles/htdocs/index.php
查询行是第43行,但由于$conn
或$db_handle
都不是false
,我无法确定它为什么是布尔值,这是为什么?< / p>
<?php
$server = "localhost";
$database = "motocross_db";
$username = "root";
$password = "";
$conn = new mysqli($server, $username, $password);
$db_handle = $conn->select_db($database);
if ($db_handle)
{
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
// upload
}
$enrollments_sql = "SELECT
users.first_name,
users.last_name,
registrations.attendance_date,
registrations.attendance_location,
bikes.bike_brand,
bikes.engine_size,
bikes.bike_type
FROM users
INNER JOIN registrations
ON users.user_id = registrations.user_id
INNER JOIN bikes
ON registrations.bike_id = bikes.bike_id";
$enrollments_result = $db_handle->query($enrollments_sql);
?>
答案 0 :(得分:5)
更改
$db_handle->query($enrollments_sql);
要
$conn->query($enrollments_sql);// use $conn here
因为mysqli_query()
需要第一个参数作为数据库连接