Php 如何修复此问题:致命错误:对非对象调用成员函数query()
我在向数据库添加结果时遇到问题。这是我的链接代码Php 如何修复此问题:致命错误:对非对象调用成员函数query(),php,mysql,Php,Mysql,我在向数据库添加结果时遇到问题。这是我的链接代码 $startingunix = strtotime($dates . " " . $startingtime); // $endingunix = strtotime($dates . " " . $endingtime); $servername = "localhost"; $username = "x"; $password = "x"; $dbname = "josfei6_ge"; // Create connection $co
$startingunix = strtotime($dates . " " . $startingtime); //
$endingunix = strtotime($dates . " " . $endingtime);
$servername = "localhost";
$username = "x";
$password = "x";
$dbname = "josfei6_ge";
// Create connection
$connection = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
date_default_timezone_set("America/Los_Angeles");
global $mysqli;
$sql="SELECT * FROM `events` WHERE `description` = '$desc' ORDER BY starttime;";
$records=mysqli_query($connection, $sql);
$numberofevents = 0;
$okay = 0;
while($eventnow=mysqli_fetch_assoc($records)){}
尝试将数据添加到数据库时出现错误:
$dbconnection->query($sql);
这给了我一个错误:
致命错误:对非对象调用成员函数query()
有人有建议吗?应该是$connection->query($sql);您有
$connection
,$dbconnection
,还有$mysqli
。。。什么给了你?@Abracadver,OP已经告诉你什么给了你-他说这给了你致命的错误;)谢谢大家!修好了!该死的,我不能投反对票。高中生应该是$connection->query($sql);您有$connection
,$dbconnection
,还有$mysqli
。。。什么给了你?@Abracadver,OP已经告诉你什么给了你-他说这给了你致命的错误;)谢谢大家!修好了!该死的,我不能投反对票。这孩子在上高中