Welcome Guest, Not a member yet? Register   Sign In
Complex Sql don't work in $this->db->query()
#1

[eluser]abmcr[/eluser]
I have try to use a complex query : this sql work fine into the SQL tab of phpadmin... and not into CI.

Code:
$sql="CREATE TEMPORARY TABLE tmptable
SELECT id FROM bacheca AS A ORDER BY id DESC LIMIT 30;
DELETE bacheca FROM bacheca WHERE id NOT in (SELECT * FROM tmptable)";
$this->db->query($sql);

The error is

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 ';DELETE bacheca FROM bacheca WHERE id NOT in (SELECT * FROM tmptable)' at line 1

CREATE TEMPORARY TABLE tmptable SELECT id FROM bacheca AS A ORDER BY id DESC LIMIT 30;DELETE bacheca FROM bacheca WHERE id NOT in (SELECT * FROM tmptable)

Any suggestion? Thank you in advance.... ciao!
#2

[eluser]richthegeek[/eluser]
I get the impression CI removes the newline characters?

Try running it with just mysql_query();

Also make sure you are running the right MySQL version?
#3

[eluser]mintbridge[/eluser]
Im guessing that it will be because mysql_query() doesn't support multiple queries, and the query string should not end with (or have) a semicolon

Paul
#4

[eluser]richthegeek[/eluser]
mysql_query DOES support multiple queries, when both the PHP and MySQL versions are on 5.x

The semicolon does matter, and is in fact meant to be there - PHP just adds it on if it's not there.
#5

[eluser]manilodisan[/eluser]
Try:
Code:
$this->db->query(preg_replace('/[\n\r]+/','',$sql));

...or try removing the new lines yourself Tongue
#6

[eluser]abmcr[/eluser]
No... i have insert all in one row, or i have try with regexp... but nothing ....it is not a CI problem, because the same sql with a normal SQL don't work.
Thank you
#7

[eluser]manilodisan[/eluser]
"DELETE bacheca FROM bacheca" Could this be an ambiguous naming?>




Theme © iAndrew 2016 - Forum software by © MyBB