Nathan
Nathan

Reputation: 15

PHP sql statement that fails in a script but works on a production server

I'm building a website and I have tested this sql statement on the production server and it works, no errors and returns the correct results. But when I execute it via php, it tells me I have an error.

$query = "SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
    select r.id, r.name from recipes r inner join fav5 f on r.id=f.recipeid where   f.memberid='$id'";

This is the error when used in a php script:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select r.id, r.name from recipes r inner join fav5 f on r.id=f.recipeid where f.' at line 2

What the heck is going on!

Upvotes: 0

Views: 105

Answers (2)

Sean Walsh
Sean Walsh

Reputation: 8344

I assume you're using mysql_query() to execute the SQL. If that's the case, that function does not support multi-queries.

You'll need to use mysqli_multi_query().

Upvotes: 0

polyhedron
polyhedron

Reputation: 1590

Cant use delimiters (;) in sql from php

It's a security issue, one line at a time.

Upvotes: 2

Related Questions