Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何修复此问题:致命错误:对非对象调用成员函数query()_Php_Mysql - Fatal编程技术网

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已经告诉你什么给了你-他说这给了你致命的错误;)谢谢大家!修好了!该死的,我不能投反对票。这孩子在上高中