0

I'm running this code in PHP:

mysql_query("SET @update_id:=NULL");
echo mysql_error();

And this is what I get:

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

Also this same code runs perfectly in PHPMyAdmin. What am I doing wrong?

Additional information. I'm trying to write a query described here: How to get ID of the last updated row in MySQL? But the problem right now is that I even can't run a simple query to create variable.

P.S. Ok, now it seems that it desn't work because of some previous queries that are not related to this one. If i move this query to the top of the php file it works. Also if I try to make this:

mysql_query("SET @update_id:=NULL; SELECT @update_id;"); It fails with syntax error. But this works fine: mysql_query("SET @update_id:=NULL;"); mysql_query("SELECT @update_id;"); Does somebody knows what am I missing here? Why can't I run two commands in one query and why they're the separate queries are related to each other?

Community
  • 1
  • 1
Andrii S
  • 41
  • 1
  • 6

2 Answers2

0
mysql_query("UPDATE your_table SET update_id=NULL");
djot
  • 2,952
  • 4
  • 19
  • 28
  • And the last updated row could be find like described here: http://de2.php.net/manual/en/function.mysql-affected-rows.php – djot Feb 03 '12 at 22:34
0

Check this it may be helpful

SELECT @update_id IN("SET @update_id:=NULL");
Sam Arul Raj T
  • 1,752
  • 17
  • 23