• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB Selection error


Is it wrong to write this query in codeigniter in this way ? Smile if yes how shall I do it ?
by the way the query is right i test it in phpmyadmin

$query = $this->db->query("SELECT 'products'.'ID', 'products'.'title', 'products'.'cID', 'p_pic'.'image', 'categories'.'title'
FROM 'p_pic'
LEFT JOIN 'shop'.'products' ON 'p_pic'.'pID' = 'products'.'ID'
LEFT JOIN 'shop'.'categories' ON 'products'.'cID' = 'categories'.'ID'
WHERE ('p_pic'.'front' =1)
         return $query->result();
the error I get :

Quote:A Database Error Occurred
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 '.'ID', 'products'.'title', 'products'.'cID', 'p_pic'.'image', 'categories'.'titl' at line 1

SELECT 'products'.'ID', 'products'.'title', 'products'.'cID', 'p_pic'.'image', 'categories'.'title' FROM 'p_pic' LEFT JOIN 'shop'.'products' ON 'p_pic'.'pID' = 'products'.'ID' LEFT JOIN 'shop'.'categories' ON 'products'.'cID' = 'categories'.'ID' WHERE ('p_pic'.'front' =1)

Filename: C:\xampp\htdocs\project\system\database\DB_driver.php

Line Number: 330

Try to remove the single quotes, CI usually rewrite the sql with safer query.

Or try to replace the single quotes with mysql quote (`) <-- the quote under the escape button

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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