• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Missing quotes on DB query

#1
I'm writing a very simple DB query and struggling with CI not enclosing my string with quotes.

The error I'm given is:
Quote:Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Horse' at line 3
SELECT `ManufacturerID` FROM (`Manufacturer`) WHERE `ManufacturerName` = Dark Horse

The error is obvious - Dark Horse should be in quotes to negate the space.

Here's my code:

Code:
$this->db->select('ManufacturerID');
$this->db->from('Manufacturer');
$this->db->where('ManufacturerName', $manufacturer);
$result = $this->db->get();

Am I missing something really obvious? I've never had to wrap quotes around variables. This is a fresh CI 2.2.0 install.
Reply

#2
I've resolved this.

I was populating the $manufacturer variable from a SimpleXML object, and it seemed to be doing something weird. Using type casting as string solved the issue.

I changed the code:
Code:
$manufacturer = (string) $response->Manufacturer;

Now everything is working as expected.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.