Re: Batch queries in the same mysql_query()
| From: | David Robley | Date: | Tue, 28 Jun 2005 11:30:50 +0000 |
| Subject: | Re: Batch queries in the same mysql_query() | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-39807@lists.php.net to get a copy of this message | ||
Denio Mariz wrote:
> Hi,
>
> I'm trying to execute multiple queries using mysql_query() function and
> I'm getting an error to check SQL syntax.
> My PHP code looks like:
>
> //-------------------------
> $sql="select x from y ; insert into y values ( 1, 2 )";
> mysql_query( $sql ) or die( mysql_error() );
> //-------------------------
>
> Maybe the problem resides on the character ";", but this queries run
> without problems when typed on "mysql" command-line tool. So, if it works
> on "mysql" command line, why it doesn't work using mysql_query() ?
>
> Any hint ?
>
If you look at php.net/mysql_query it will tell you that the query shouldn't
end with a semicolon ";" What it really should say is the query shouldn't
_contain_ a semicolon. This is php attempting to protect you from SQL
injection.
Just do a separate mysql_query for each query.
Cheers
--
David Robley
Friction can be a drag sometimes.