note 26181 deleted from function.mysql-query by didou
| From: | didou@php.net | Date: | Sat, 17 May 2003 18:55:49 +0000 |
| Subject: | note 26181 deleted from function.mysql-query by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-48209@lists.php.net to get a copy of this message | ||
Note Submitter: inf8@grandmother.ch
Well, this multi-query-thing might be usefull if you want to import an exported sql-table (e.g. with
phpmysql). There is no security hole in this case...
So, here's my version of this function (now able to handle comments and blank lines!):
function mysql_fquery($sql_file) {
/* file exists? load into array */
if(!($a = @file($sql_file)))
return false;
/* remove comments (#) */
foreach($a as $i => $l) {
$a[$i] = trim($l);
if(substr($a[$i], 0, 1)=="#" || empty($l))
unset($a[$i]);
}
/* split commands and execute */
$a = explode(';', implode('', $a));
foreach($a as $q) {
if(trim($q)=="") break;
if(!@mysql_query($q)) {
return false;
}
}
return true;
}