note 56636 added to function.mysql-query
| From: | celtic at raven-blue dot com | Date: | Sat, 10 Sep 2005 14:03:51 +0000 |
| Subject: | note 56636 added to function.mysql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94987@lists.php.net to get a copy of this message | ||
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 = "";
}
}
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.mysql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56636
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56636&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56636&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56636&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56636&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56636&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56636&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56636&report=yes
Search -- http://master.php.net/manage/user-notes.php