1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-12 00:54:11 +02:00

* dibi::loadFile() extreme fast SQL dump loading

This commit is contained in:
David Grudl
2008-01-12 01:20:23 +00:00
parent de4a882788
commit da0a239d6d
3 changed files with 65 additions and 2 deletions

View File

@@ -388,6 +388,40 @@ class DibiConnection extends NObject
/**
* Import SQL dump from file - extreme fast!
*
* @param filename
* @return int count of sql commands
*/
public function loadFile($file)
{
$this->connect();
@set_time_limit(0);
$handle = @fopen($file, 'r');
if (!$handle) {
throw new DibiException("Cannot open file '$file'");
}
$count = 0;
$sql = '';
while (!feof($handle)) {
$s = fgets($handle);
$sql .= $s;
if (substr(rtrim($s), -1) === ';') {
$this->driver->query($sql);
$sql = '';
$count++;
}
}
fclose($handle);
return $count;
}
/**
* Gets a information of the current database.
*
@@ -405,7 +439,7 @@ class DibiConnection extends NObject
*/
public function __wakeup()
{
throw new DibiException('You cannot serialize or unserialize '.__CLASS__.' instances');
throw new DibiException('You cannot serialize or unserialize ' . $this->getClass() . ' instances');
}
@@ -415,7 +449,7 @@ class DibiConnection extends NObject
*/
public function __sleep()
{
throw new DibiException('You cannot serialize or unserialize '.__CLASS__.' instances');
throw new DibiException('You cannot serialize or unserialize ' . $this->getClass() . ' instances');
}
}