CodeIgniter Forums
DB Selection error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: DB Selection error (/showthread.php?tid=38393)



DB Selection error - El Forum - 02-07-2011

[eluser]Unknown[/eluser]
Hi

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

Code:
$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



DB Selection error - El Forum - 02-11-2011

[eluser]abedzilla[/eluser]
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