Home » Database » DB » Bug #2828
execute SQL Script file
Details
| Request #2828 | execute SQL Script file |
|---|---|
| Submitted | 2004-11-25 13:31 UTC |
| From | andre dot steffens at adress-research dot de |
| Assigned | danielc |
| Status | Wont fix |
| Package | DB |
| PHP Version | 4.3.9 |
| OS | Win2k |
| Roadmaps | (Not assigned) |
Comments
[2004-11-25 13:31 UTC] andre dot steffens at adress-research dot de
Description:
------------
It would be nice to simulate the execute of a SQL script file. If the DB supports transactions, the complete execution can run as transaction.
example:
<-- test.sql -->
create table t1 ...;
create table t2 ...;
update t3 set ...
<-- php -->
...
$db->runFile('test.sql');
...
[2004-12-03 16:39 UTC] andre dot steffens at adress-research dot de
What do you think about the following solution?
// {{ runFile()
function runFile($file)
{
if (!isset($file) || !is_file($file)) {
return $this->raiseError(DB_ERROR_NOT_FOUND);
}
$fid = fopen($file, 'rb');
$arr = explode(";\r\n", fread($fid, filesize($file)));
fclose($fid);
if (!empty($arr)) {
foreach ($arr as $query) {
$query = trim(preg_replace("=\/\*.*\*\/=", "", $query));
if ($query) {
if ($this->isError($x = $this->query($query))) {
return $x;
}
}
}
}
return true;
}
// }}