0

So I use this code to connect to MySQL and execute multiple statements:

$connect=@mysql_connect($host,$user,$pass,false,65536) or die("Can't connect");
mysql_select_db($base,$connect);

When connected I do:

mysql_query("CREATE TABLE IF NOT EXISTS tablename ...;\nINSERT INTO tablename ...;");

I use this code to execute backup files containing the same code above (\n=new line). When I run this script on my webpage (hosted server) it works but on my local computer where I use XAMPP it shows an 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 'INSERT INTO tablename' at line 2

I have checked php.ini and I have safe_mode = Off and sql.safe_mode = Off too.

Any ideas what am I missing?

Remc4
  • 1,044
  • 2
  • 12
  • 24
  • Remove the `\n` as it isn't a valid SQL token. – Ben Sep 29 '11 at 21:27
  • Thanks, but in the file it is acutually a new line, I typed `\n` just to make it simpler. PHP actually converts it to a new line anyway. – Remc4 Sep 29 '11 at 21:30

1 Answers1

0

According to the PHP manual, mysql_query does not support multiple queries. However, in the comments there's a guy stating that it it possible:

However, multiple queries seem to be supported. You just have to pass flag 65536 as mysql_connect's 5 parameter (client_flags). (Source)

On the other hand, manual only mentions two parameters to the function, so I wonder what we are supposed to pass as the 3rd and 4th parameters if that 5th one really does the trick!

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • You were probably looking in the `mysql_query` manual, `mysql_connect` function does have 5 parameters. I am passing that nubmer to `mysql_connect` and it works on my hosted server when I run multiple statements, but not on localhost (XAMPP). – Remc4 Sep 29 '11 at 21:39