0

Here is my full SQL query (variable named $query) that I'm echo'ing out right before the actual query:

UPDATE wp_portfolio_items SET caption='This is a caption',item_order=1,image='20130705104136Layer-651.jpg' WHERE id=1; UPDATE wp_portfolio_items SET caption='This is another caption',item_order=2,image='20130705104137photo.JPG' WHERE id=2; 

If I copy that query and run it in phpMyAdmin's SQL tab, it runs fine and updates the two rows. However, when this is queried in WordPress it gives this WordPress error:

WordPress database error: [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 'UPDATE wp_portfolio_items SET caption='This is another caption',item_order=2,ima' at line 1] UPDATE wp_portfolio_items SET caption='This is a caption',item_order=1,image='20130705104136Layer-651.jpg' WHERE id=1; UPDATE wp_portfolio_items SET caption='This is another caption',item_order=2,image='20130705104137photo.JPG' WHERE id=2;

I doubt this is necessary to include, but I'll do it anyways. This is the code where I run the query:

    if ($query != "") {
        echo $query . "<br><br>";
        $wpdb->show_errors();
        $wpdb->query($query);
        exit;
    }

Any ideas why WordPress would have a problem with this query, but phpMyAdmin can run it just fine?

1
  • Can you please show us $query variable which you defined with that query? Commented Jul 5, 2013 at 11:01

1 Answer 1

2

You can't run multiple queries in a single statement.

phpMyAdmin parses the SQL you enter so it handles multiple queries by extracting them and executing them one by one.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah. I tried it with a single query and it gave me the same error, so I figured it wasn't the multiple queries. However, I just realized I still had the semicolon at the end, and removing the semicolon fixed it. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.