note 97099 deleted from function.mysql-query by danbrown
| From: | danbrown@php.net | Date: | Thu, 01 Apr 2010 13:37:30 +0000 |
| Subject: | note 97099 deleted from function.mysql-query by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167618@lists.php.net to get a copy of this message | ||
Note Submitter: atrandafirc at yahoo dot com
----
Just a quick change on lanbotdevman's parse_mysql_dump function he posted above, I used it and
it failed sometimes because of some white spaces not locating the query end specified by
';'
The only modification is to apply a trim to each sql line that is being read:
<?php
function parse_mysql_dump($url) {
$handle = @fopen($url, "r");
$query = "";
while(!feof($handle)) {
$sql_line = trim(fgets($handle)); // <-- Trim added here
if (trim($sql_line) != "" && strpos($sql_line, "--") === false)
{
$query .= $sql_line;
if (preg_match("/;[\040]*\$/", $sql_line)) {
$result = mysql_query($query) or die(mysql_error());
$query = "";
}
}
}
}
?>