你好,我目前正試圖連接我的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