How to run a set of SQL queries from a file, in PHP?

Posted by Harish Kurup on Stack Overflow See other posts from Stack Overflow or by Harish Kurup
Published on 2010-06-05T12:33:30Z Indexed on 2010/06/05 12:42 UTC
Read the original article Hit count: 202

Filed under:
|
|

I have some set of SQL queries which is in a file(i.e query.sql), and i want to run those queries in files using PHP, the code that i have wrote is not working,

//database config's...
$file_name="query.sql";
$query==file($file_name);
$array_length=count($query);
for($i=0;$i<$array_length;$i++)
{
    $data .= $query[$i];
}

echo $data;    
mysql_query($data);

it echos the SQL Query from the file but throws an error at mysql_query() function...

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql