Page 1 of 1

Running MySQL query from a php file

Posted: Tue Jun 12, 2007 3:07 pm
by Jay695
Hi

I am trying to run a series of sql queries through PHP code. The queries are created on my client machine by automated code and are uploaded to the server.

The same queries (it is a series of 30 to 60 "SELECT" and "INSERT" queries) work fine if I paste them together in the PhpMyAdmin window. Or use the file browse feature of PhpMyAdmin.

However when I try to run them using PHP code it fails. I verified connection to the server. I can also run other simple select queries if I hardcode them.

Here is the extract of my code.

Code: Select all

$file = 'sql.txt';
  $content = file_get_contents($file);
  echo $content;
  mysql_query($content, $conn);
What am I doing wrong? The file ("sql.txt") is created on a windows machine and uploaded to the Unix MySQL server using ASCII mode.

Thank you

Posted: Tue Jun 12, 2007 3:55 pm
by RobertGonzalez
Can you post some queries? I think it has to do with not doing something with the result returned by the query. But as I write that it doesn't sound right.

Posted: Tue Jun 12, 2007 4:43 pm
by John Cartwright

Code: Select all

mysql_query($content, $conn) or die(mysql_error());
What does this yieldÉ

Posted: Tue Jun 12, 2007 5:30 pm
by Benjamin
mysql_query will only execute 1 query.