note 56636 deleted from function.mysql-query by philip
| From: | philip@php.net | Date: | Fri, 04 Sep 2015 19:20:43 +0000 |
| Subject: | note 56636 deleted from function.mysql-query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203648@lists.php.net to get a copy of this message | ||
Note Submitter: celtic at raven-blue dot com
----
Here's a revision of ix at nivelzero -and- thomas at pixur's code. This SQL dump parser
fixes the check for comments that was present in the old (ie. a '--' located anywhere in
the string would make it ignore that line!), and adds the check for the # comment. That had me
thinking.
<?php
function parse_mysql_dump($url, $ignoreerrors = false) {
$file_content = file($url);
$query = "";
foreach($file_content as $sql_line) {
$tsl = trim($sql_line);
if (($sql != "") && (substr($tsl, 0, 2) != "--") &&
(substr($tsl, 0, 1) != "#")) {
$query .= $sql_line;
if(preg_match("/;\s*$/", $sql_line)) {
$result = mysql_query($query);
if (!$result && !$ignoreerrors) die(mysql_error());
$query = "";
}
}
}
}
?>