Running MySQL query from a php file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Jay695
Forum Newbie
Posts: 1
Joined: Tue Jun 12, 2007 2:51 pm

Running MySQL query from a php file

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

mysql_query($content, $conn) or die(mysql_error());
What does this yieldÉ
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

mysql_query will only execute 1 query.
Post Reply