CodeIgniter Forums
query problem - 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: query problem (/showthread.php?tid=11605)



query problem - El Forum - 09-16-2008

[eluser]dimis[/eluser]
I use this code
Code:
foreach ($lans as $lan)
        {
(".$lan['code'].",".$lan['name'].",".$id.")");
$sql = "replace into material_lan ( lan_id ,lan_text,material_id) values (?,?,?)";
            $this->db->query($sql,$lan['code'], $lan['name'],$id);

        }
and i have this error
Code:
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 '' at line 1

replace into material_lan ( lan_id ,lan_text,material_id) values ('en',
What is wrong ? I run this sql at sql manager lite and it is ok


query problem - El Forum - 09-16-2008

[eluser]Bramme[/eluser]
Try with an alternative syntax maybe...

Code:
$qry = "REPLACE INTO material_lan SET lan_id = "$value".."; // etc, you get the picture

It might be possible CodeIgniter messes up your syntax, not sure though.


query problem - El Forum - 09-16-2008

[eluser]Sumon[/eluser]
I think, you mixed up something.
You might expect either
Code:
$sql = "insert into material_lan ( lan_id ,lan_text,material_id) values ($lan['code'],$lan['name'],$id)";
or
Code:
$data = array(
               'lan_id' => $lan['code'] ,
               'lan_text' => $lan['name'] ,
               'material_id' => $id
            );
$this->db->insert('material_lan', $data);



query problem - El Forum - 09-16-2008

[eluser]dimis[/eluser]
replace is a statement of mysql (I thing only).
At my situation i thing it was buggy so I change it to update.


query problem - El Forum - 09-16-2008

[eluser]Michael Wales[/eluser]
You can use $this->output->enable_profiler(TRUE) to always see exactly what CI is sending to your database - great for catching little quirks where ActiveRecord isn't behaving as you would expect it to.