zogby
zogby

Reputation: 482

mysql syntax error only when executed by php

I got this request:

"START TRANSACTION; DELETE FROM `awaiting_auth` WHERE `code` = '06b8465eed00727a1eac49fae89b88f876ded2eb' LIMIT 1; INSERT IGNORE INTO `prsn` SET `login` = 'new_user', `passwd` = '40bd001563085fc35165329ea1ff5c5ecbdbbeef', `color` = '#cbc5f2'; COMMIT;"

And I receive this error:

"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 FROM awaiting_auth WHERE code = '06b8465eed00727a1eac49fae89b88f876de' at line 1".

However when executing sql via terminal everything goes well and no errors are thrown.
What is wrong with my request? Thanks in advance.

Upvotes: 1

Views: 81

Answers (4)

vicentazo
vicentazo

Reputation: 1799

Try to execute each statement individually:

START TRANSACTION;
DELETE FROM `awaiting_auth` WHERE `code` = '06b8465eed00727a1eac49fae89b88f876ded2eb' LIMIT 1;
INSERT IGNORE INTO `prsn`(`login`, `passwd`, `color`) VALUES('new_user','40bd001563085fc35165329ea1ff5c5ecbdbbeef', '#cbc5f2');
COMMIT;

Upvotes: 0

vidario
vidario

Reputation: 479

You must split the queries in separate ->query() calls. The SQL console does that automatically. E.g.

->query("START TRANSACTION");
->query("DELETE FROM...");

Upvotes: 2

Your Common Sense
Your Common Sense

Reputation: 157839

Just run these queries one by one, not in single packet.

Upvotes: 0

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

One operation per query. So you need to split your query into single queries.

Upvotes: 0

Related Questions