我有一个选择查询,当在phpMyAdmin中执行时会返回正确的值。但是,当尝试在php中执行时,PDO在某些字段中返回null。
public function showAllEventsDetails($userId)
{
$results = parent::hardCodeSelect("select * from events inner join address_details on events.address_id = address_details.address_id
inner join event_category on events.event_category_id = event_category.event_category_id
inner join users on users.user_id = events.coordinator_id left join participation
on participation.user_id = ". $userId ." and events.event_id = participation.event_id");
return $results;
}
public function hardCodeSelect($sql)
{
try {
if( !$this->conn->prepare($sql) ){
throw new \Exception(1,"Error Processing Request");
}
$this->query = $this->conn->prepare($sql);
$this->query->execute();
$results = $this->query->fetchAll(PDO::FETCH_ASSOC);
$this->logger->log(01, json_encode($results));
return $results;
}
catch (PDOException $e){
$this->logger->log($e->getCode() , $e->getMessage());
}
catch (\Exception $e) {
$this->logger->log($e->getCode() , $e->getMessage());
}
}
OUTPUT i got in slim framework
[2019-02-05 22:28:43] Event_Management_db.ERROR: [{"event_id":"1","event_name":"event name ","event_category_id":"1","event_photo":null,"coordinator_id":"29","event_date":"2019-02-01","start_time":"12:00:00","end_time":"01:00:00","spots":"4","address_id":"23","street_address":"event street","area":"event area","pincode":"777777","event_category_name":"party","user_id":"1","user_name":"santhosh","user_email":"sandy@gmail.com","password":"sandy","profile_pic":"profile_pics\/0b90b4eb912d7d67.png","phone_number":"123451234","organisation_website":null,"role_id":"1","participation_id":"28"},{"event_id":"3","event_name":"wer","event_category_id":"1","event_photo":null,"coordinator_id":"31","event_date":"2190-12-12","start_time":"12:03:00","end_time":"12:03:00","spots":"100","address_id":"33","street_address":"qwe","area":"qwe","pincode":"123","event_category_name":"party","user_id":"1","user_name":"zilker","user_email":"zilker@zilker.com","password":"zilker","profile_pic":"profile_picsd9851d05e9f694c1.png","phone_number":"12","organisation_website":null,"role_id":"1","participation_id":"29"},{"event_id":"2","event_name":"cinema","event_category_id":"1","event_photo":null,"coordinator_id":"17","event_date":"2109-03-12","start_time":"12:00:00","end_time":"03:00:00","spots":"100","address_id":"20","street_address":"zilker street","area":"zilker","pincode":"27","event_category_name":"party","user_id":"1","user_name":"pongal","user_email":"pongal@gmail.com","password":"pongal","profile_pic":"profile_pics\/0b90b4eb912d7d67.png","phone_number":"11111","organisation_website":null,"role_id":"1","participation_id":"30"},{"event_id":null,"event_name":"marathon","event_category_id":"1","event_photo":null,"coordinator_id":"31","event_date":"2190-12-12","start_time":"12:03:00","end_time":"12:03:00","spots":"100","address_id":"33","street_address":"qwe","area":"qwe","pincode":"123","event_category_name":"party","user_id":null,"user_name":"zilker","user_email":"zilker@zilker.com","password":"zilker","profile_pic":"profile_picsd9851d05e9f694c1.png","phone_number":"12","organisation_website":null,"role_id":"1","participation_id":null},{"event_id":null,"event_name":"Asus Launch","event_category_id":"1","event_photo":null,"coordinator_id":"1","event_date":"2019-03-20","start_time":"12:00:00","end_time":"09:00:00","spots":"100","address_id":"1","street_address":"asus street","area":"asus street","pincode":"123","event_category_name":"party","user_id":null,"user_name":"krishna","user_email":"krishna@gmail.com","password":"veronica","profile_pic":"453423","phone_number":"3333333","organisation_website":null,"role_id":"1","participation_id":null},{"event_id":null,"event_name":"Lenovo Launch","event_category_id":"1","event_photo":null,"coordinator_id":"1","event_date":"2019-03-12","start_time":"09:00:00","end_time":"04:00:00","spots":"34","address_id":"1","street_address":"lenovo street","area":"lenovo area ","pincode":"123456","event_category_name":"party","user_id":null,"user_name":"krishna","user_email":"krishna@gmail.com","password":"veronica","profile_pic":"453423","phone_number":"3333333","organisation_website":null,"role_id":"1","participation_id":null},{"event_id":null,"event_name":"Petta party","event_category_id":"1","event_photo":null,"coordinator_id":"1","event_date":"2019-03-12","start_time":"12:00:00","end_time":"23:00:00","spots":"134","address_id":"1","street_address":"petta street","area":"petta area ","pincode":"777","event_category_name":"party","user_id":null,"user_name":"krishna","user_email":"krishna@gmail.com","password":"veronica","profile_pic":"453423","phone_number":"3333333","organisation_website":null,"role_id":"1","participation_id":null},{"event_id":null,"event_name":"sony launch","event_category_id":"1","event_photo":null,"coordinator_id":"1","event_date":"2019-09-12","start_time":"10:00:00","end_time":"23:00:00","spots":"45","address_id":"1","street_address":"sony strret","area":"sony area ","pincode":"1212","event_category_name":"party","user_id":null,"user_name":"krishna","user_email":"krishna@gmail.com","password":"veronica","profile_pic":"453423","phone_number":"3333333","organisation_website":null,"role_id":"1","participation_id":null}] [] []
这里的event_id为null,在phpMyAdmin中执行时不是。