PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #2828

execute SQL Script file

Details

Request #2828execute SQL Script file
Submitted2004-11-25 13:31 UTC
Fromandre dot steffens at adress-research dot de
Assigneddanielc
StatusWont fix
PackageDB
PHP Version4.3.9
OSWin2k
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;
}
// }}