note 26181 added to function.mysql-query

From: Date: Mon, 21 Oct 2002 19:11:36 +0000
Subject: note 26181 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-38379@lists.php.net to get a copy of this message
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; } -- http://www.php.net/manual/en/function.mysql-query.php http://master.php.net/manage/user-notes.php?action=edit+26181 http://master.php.net/manage/user-notes.php?action=delete+26181 http://master.php.net/manage/user-notes.php?action=reject+26181

« previous php.notes (#38379) next »