gpt4 book ai didi

php - fatal error : Call to a member function execute() on boolean

转载 作者:太空宇宙 更新时间:2023-11-03 11:49:32 30 4
gpt4 key购买 nike

<?php
session_start();
$config = parse_ini_file('../database_config.ini');
//Create Database connection
$connection = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);

if ($connection->connect_error) {
die('Could not connect to db: ' . mysql_error());
}


$stmt = $connection->prepare("INSERT INTO report (reportID, userID, description, address, postalcode, latitude, longitude)
VALUES(0, 007, 'Major fire', 'Jurong Point', 640724, 1.640724, 103.640724)");

$stmt->execute();
echo "Error:\n";
print_r($stmt->error_list);
$stmt->close();

$connection->close();
?>

错误: fatal error :调用 bool 值上的成员函数 execute()

为什么我的 prepare 语句会失败?

我的报告表的结构 enter image description here

最佳答案

您正在将面向对象的风格与正常的过程 mysqli 风格相结合。在您使用的第 5 行。

mysqli_connect()

在第 12 行你使用。

$connection->prepare()

这是行不通的,如果您将 $connection 更改为面向对象的样式,就像您对 prepare 语句所做的那样,它将行得通。

$connection = new mysqli('localhost', $config['username'], $config['password'], $config['dbname'])

可以在此处找到更多信息 http://php.net/manual/en/mysqli.prepare.php

关于php - fatal error : Call to a member function execute() on boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36329555/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com