mySQL error in PHP that works directly in mySQL

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default mySQL error in PHP that works directly in mySQL

    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
    jcg Guest

  2. Similar Questions and Discussions

    1. ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
      When i try to start my mysql server, i get this error ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'...
    2. can't verify mySQL datasource - works in mySQL, but notin CF7
      I can't verify a local mySQL datasource in ColdFusion 7 admin. I am using Dreamweaver MX 2004 with the CF7 extensions installed. I am developing...
    3. Going directly to a MySQL Database Record
      Hello, For a few days now I have been trying to do what I suspected isn't too difficult. I have a MySQL database of user profiles. I want my...
    4. php evaluated directly by mysql and not the webserver ?
      Hi there Out of curiosity .... Long time ago I was working with Infomix (now IBM) Universal Server, that had a data type 'html' implemented as...
    5. using $_SESSION directly in mysql query
      Marcus wrote: $query = "SELECT field FROM {$_SESSION} WHERE name='{$_SESSION}'"; .... a) You need to quote your array keys (unless they're...
  3. #2

    Default Re: mySQL error in PHP that works directly in mySQL


    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
    [url]www.creative-light.com[/url]
    tom (at) creative (dash) light (dot) com
    do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
    Tom Thackrey Guest

  4. #3

    Default Re: mySQL error in PHP that works directly in mySQL

    > > 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 ;
    >
    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


    Joel Goldstick Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139