For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2004 > mySQL error in PHP that works directly in mySQL









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mySQL error in PHP that works directly in mySQL
jcg

2004-05-24, 11:33 pm

Hi,

I created this query:
CREATE TEMPORARY TABLE tmp SELECT photos.Name FROM photos LEFT JOIN
PhotoNames ON ( photos.Name = PhotoNames.Name ) WHERE (PhotoNames.Name IS
NULL);# DELETE photos FROM photos, tmp WHERE (photos.Name = tmp.Name) ;


With this code:

$sql = "CREATE TEMPORARY TABLE tmp SELECT photos.Name"
. " FROM photos"
. " LEFT JOIN PhotoNames ON ( photos.Name = PhotoNames.Name ) "
. " WHERE (PhotoNames.Name IS NULL);#"
. " DELETE photos FROM photos,"
. " tmp WHERE (photos.Name = tmp.Name) ;"
. "";

echo "<br>$sql<br>";
$result = mysql_query("$sql");
if (!$result) {
die("query failed: " . mysql_error());
}
echo "<br>Pruning deleted photos<br>";

And I get this:

query failed: 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
';# DELETE photos FROM photos, tmp WHERE (photos.Name = tmp.Name


I created the sql code with phpmyadmin directly. Anyone see my error?

Joel Goldstick
Columbus, OH
Tom Thackrey

2004-05-25, 3:34 am


On 24-May-2004, jcg <hpwebby@ameritech.net> wrote:

> I created this query:
> CREATE TEMPORARY TABLE tmp SELECT photos.Name FROM photos LEFT JOIN
> PhotoNames ON ( photos.Name = PhotoNames.Name ) WHERE (PhotoNames.Name IS
> NULL);# DELETE photos FROM photos, tmp WHERE (photos.Name = tmp.Name) ;
>
>
> With this code:
>
> $sql = "CREATE TEMPORARY TABLE tmp SELECT photos.Name"
> . " FROM photos"
> . " LEFT JOIN PhotoNames ON ( photos.Name = PhotoNames.Name ) "
> . " WHERE (PhotoNames.Name IS NULL);#"
> . " DELETE photos FROM photos,"
> . " tmp WHERE (photos.Name = tmp.Name) ;"
> . "";
>
> echo "<br>$sql<br>";
> $result = mysql_query("$sql");
> if (!$result) {
> die("query failed: " . mysql_error());
> }
> echo "<br>Pruning deleted photos<br>";
>
> And I get this:
>
> query failed: 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
> ';# DELETE photos FROM photos, tmp WHERE (photos.Name = tmp.Name
>
>
> I created the sql code with phpmyadmin directly. Anyone see my error?


phpmyadmin allows multiple sql statements and comments, mysql_query() does
not. Remove everything after the first ;

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Joel Goldstick

2004-05-25, 7:34 am


IS[color=darkred]
that[color=darkred]
near[color=darkred]
>
> phpmyadmin allows multiple sql statements and comments, mysql_query() does
> not. Remove everything after the first ;
>

Thanks Tom! So, my best course of action is to create a normal table
instead of temporary, then perform each operation after the next with 3
mysql_query statements?

Joel Goldstcik


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com