Reputation: 153
I'm having a problem with selecting data from my database. It show me following error
A Database Error Occurred
Error Number: 1054
Unknown column 'BA' in 'where clause'
SELECT * FROM crime_details INNER JOIN crime_slink ON crime_slink.report_ID =crime_details.report_ID INNER JOIN crime_suspect ON crime_suspect.id=crime_slink.suspect_id INNER JOIN crime_vlink ON crime_vlink.report_ID=crime_details.report_ID INNER JOIN crime_victim ON crime_victim.id=crime_vlink.victim_id WHERE crime_details.report_ID =BA-12-00002
Filename: C:\xampp\htdocs\CNPPO\system\database\DB_driver.php
Line Number: 330
It seems like the problem is in this part WHERE crime_details.report_ID =BA-12-00002
I think the problem was caused by the dashes or hyphens in my query.
Im using $this->db-query()
function of codeigniter for my queries.
Upvotes: 3
Views: 1058
Reputation: 42440
crime_details.report_ID
holds a VARCHAR
, so your where condition should be
WHERE crime_details.report_ID = 'BA-12-00002'
i.e., you need to wrap the value in quotes.
Also, instead of using $this->db->query()
to run your hand-written MySQL query, you should use ActiveRecord's query builder which would have taken care of this for you. For example, you could have done:
$query = $this->db->get_where('crime_reports', array( 'report_ID' => 'BA-12-00002' ));
Upvotes: 2
Reputation: 77956
Change
WHERE crime_details.report_ID =BA-12-00002
to
WHERE crime_details.report_ID = "BA-12-00002"
Upvotes: 1