你好,我目前正试图连接我的PHP文件到数据库,但由于某种原因,我不断收到这个错误返回给我试图获得非对象的属性。这似乎是一个问题,查询自己是来自第23行的自我,但我不能在我的生活中看到问题。这是我的代码任何帮助将不胜感激。试图获取非对象的属性,准备好的语句
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("dbconnect.php");
//get first 3 months
$month = '%'.$_POST['month'].'%';
//month 1 and 2 are currently not in use till issue is fixed
$month2 = '%'.$_POST['month'].'%';
$month3 = '%'.$_POST['month'].'%';
echo $month;
//connect to database and prepare mysqli statement to get day, title, details, time and location if month has any details
//will be adding more details for this statement to get once it is fully tested
if($connect->connect_errno){
printf("connection failed, please try again and if this error occurs again please submit this bug through the contact us page", $connect->connect_error);
exit();
}
$CalendarDetails = $connect->prepare("SELECT `date`, `time`, `title`, `details`, `eventLocation`, `longitude`, `latitude` FROM `calendar` WHERE `date` LIKE ?");
//$CalendarDetails = $connect->prepare("SELECT date, time, title, details, eventLocation, longitude, latitude FROM calendar WHERE date LIKE ?");
//check if connection succeeded
//if (false===$CalendarDetails) {
//error occurs in line below
// die('failed error 1 ' . htmlspecialchars($CalendarDetails->error));
//}
//bind the month to the prepared statement
$CalendarDetails->bind_param("s", $month);
//check if failed
//if (false===$CalendarDetails) {
// die('failed error 2 ' . htmlspecialchars($CalendarDetails->error));
//}
//execute query
$CalendarDetails->execute();
//check if failed
//if (false===$CalendarDetails) {
// die('failed error 3 ' . htmlspecialchars($CalendarDetails->error));
//}
//store results
$CalendarDetails->store_result();
//if (false===$CalendarDetails) {
// die('failed error 4 ' . htmlspecialchars($CalendarDetails->error));
//}
//bind results to separate variables
$CalendarDetails->bind_result($date, $time, $title, $details, $time, $location, $longitude, $latitude);
//get results
if($day != null){
if($month != null){
//create an array to store results and send to app
//$Allevents = array();
$i = 0;
$event[$i] = array();
while($CalendarDetails->fetch()){
$j = strval($i);
//this will combine all results into one string and will be split into an array in java
$event[$j] = $date. "|". $title. "|". $details. "|". $time. "|". $location. "|". $longitude. "|". $latitude;
/*$event['day'][$i] = $day;
$event['title'][$i] = $title;
$event['details'][$i] = $details;
$event['time'][$i] = $time;
$event['location'][$i] = $location;
$event['longitude'][$i] = $longitude;
$event['latitude'][$i] = $latitude;*/
//$Allevents[$i] = $event;
$i++;
}
echo json_encode($event);
mysqli_stmt_close($CalendarDetails);
}else{
echo "month not sent from app";
}
}else{
echo "no events this month";
}
?>
更新DBCONNECT文件代码
$connect= new mysqli("127.0.0.1",$config['username'],$password,$config['dbname'], 3306);
更新2我都谈到了关于该查询的if语句,我现在得到的是
$CalendarDetails->bind_param("s", $month);
线26类似的错误
我现在收到的错误是: 调用一个非对象的成员函数bind_param()
更新3 我的准备语句失败的原因是由于拼写错误,我的数据库中的日历拼写错误。
'$ event [$ j] = $ date +“|” + ......'那些应该是点,而不是加号。 –
“来自20号线” - 什么是20号线? – FuzzyTree
谢谢你,我会改变这一点,混合php与Java连接哈哈。 – noob