note 49385 added to function.mysql-query

From: Date: Wed, 26 Jan 2005 10:54:23 +0000
Subject: note 49385 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-84014@lists.php.net to get a copy of this message
Here is a multiple query function that takes the char ; as a delimiter. Also, the splitting of the query is done by a regular expression, so it doesn't matter if the character ; appears slashed in a sql command: <?php function multipleQuery($query) { // spliting the query $queryArray = preg_split( '/(?<![;\\\\])'. '(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'. '|\\\\\\\\\\\\\\\\\\\\\\\\;'. '|\\\\\\\\\\\\\\\\;|\\\\\\\\;|;)/' ,$query); foreach ($queryArray AS $query) { $query = trim($query); if (!empty($query)) { mysql_query($query, $link); if (mysql_error($link)) trigger_error('<B>MYSQL ERROR -</B> '.mysql_errno($link).' '.mysql_error($link). '<BR/><B>SQL:</B>'.$query, E_USER_ERROR); } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49385 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49385&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49385&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49385&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49385&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49385&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+49385&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#84014) next »