Tuesday, March 3, 2009

Run a .SQL file from PHP

Execute a .SQL file from PHP code

// executes the SQL commands from an external file.

$file = "sqlQueryfile.sql";
//Check if file exists
if (!file_exists($file))
{
die("Error : "The file $file does not exist.");
}

$str = file_get_contents($file);
if (!$str)
{
die("Error : Unable to read the contents of $file.");
}

$this->last_query = $str;

// split all the query's into an array
$sql = explode(';', $str);
foreach ($sql as $query)
{
if (!empty($query))
{
$r = mysql_query($query);
if (!$r)
{
die("Error : "mysql_error());

}
}
}

2 comments:

  1. FUTURE BLUE CHIP BUY NSE #COALINDIA ABOVE 280 TARGET 283-285 SL 276.5
    OUR FIRST TGT 283 IN COALINDIA BUY CALL, ONCE BOOK PARTIAL PROFIT NOW 282 AND TRAIL SL AT COST
    Free Tips

    ReplyDelete
  2. Technical Strategies showed here with best example. Nice to read daily
    Trade India Research Reviews

    ReplyDelete

Express you views