• Issue:

    I am making PHP build a MySQL statement inside of a string, based on changes it detects in an array.

    The following statement succeeds with $wpdb->query()

    UPDATE MyTable_artists SET first_name = "Jacob", thumbnail = "Option 2" WHERE id = "1";

    However, the following statement fails with $wpdb->query()

    UPDATE MyTable_artists SET first_name = "Jacob", thumbnail = "Option 2" WHERE id = "1"; UPDATE MyTable_artists SET thumbnail = "Option 2" WHERE id = "2"; UPDATE MyTable_artists SET thumbnail = "Option 2" WHERE id = "4";

    Extra Info:

    The statement only seems to succeed when running a single UPDATE. More than one UPDATE statement seems to cause a failure.

    This is strange in that running the multiple UPDATE statements through PhpMyAdmin does not produce any errors.

    Running the string variable through a var_dump() does not reveal any strange characters hiding within the string.

    Solution:

    No solution yet – Any insights or suggestions are greatly appreciated, and I will update this ticket once I discover what is wrong.

Viewing 1 replies (of 1 total)
  • Thread Starter korythewebguy

    (@korythewebguy)

    Update 5/12/09:

    After some research, it seems that this is a limitation of PHP. The limitation is not expected to be remedied because many sysadmins feel this is a security feature to prevent massive SQL injection attacks.

    While PhpMyAdmin appears to be able to run multiple statements at once, in reality it’s because phpMyAdmin parses the statements into individual queries, then runs them.

    For the moment I guess I’ll just accept this and look for a work-around, but I’m greatly hoping someone will come along and prove me incorrect.

    Many thanks to everyone who has taken the time to read this, and even moreso to those who offer suggestions or information.

Viewing 1 replies (of 1 total)
  • The topic ‘$wpdb->query() fails when multiple UPDATE statements are used’ is closed to new replies.