<?php
// splitsql.php - executing an SQL file
// (c) 2006 legolas558
// Public Domain
include 'gladius/gladius.php';
$G = new Gladius();
function split_sql(&$sql) {
if
(preg_match_all('/(insert|drop|create|select|delete|update|use|truncate|show|describe|rename('._G__STRING.')?)*;/i', $sql, $m))
return $m[0];
else
return array();
}
// load the queries from file myfilename.sql
$sql = file_get_contents('myfilename.sql');
$queries = split_sql($sql);
unset($sql);
foreach ($queries as $query) {
$time_start = array_sum(explode(' ', microtime()));
// execute the SQL statement
$rs = $G->Query($query);
// show the query and the execution time
echo '<pre>'.$query.'</pre>Executed in '.(array_sum(explode(' ', microtime()))
- $time_start).' seconds<br>Result: ';
// show the return value or resultset
if
(is_bool($rs))
print_r($rs);
else
print_r($rs->GetArray());
echo $G->errstr.'<hr>';
}
?>