Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7582577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:28:08+00:00 2026-05-30T18:28:08+00:00

I ran in to this problem in one of my live web apps. It

  • 0

I ran in to this problem in one of my live web apps. It seems that if you issue a multi-statement query to MySQL via PHP PDO, and the first statement is an insert statement, and the second statement is an update statement, the PDO::nextRowset() function doesn’t return the right number of result sets. (Note that PDO supposedly supports multiple statements per MySQL query since PHP 5.3.)

Here’s an example:

SQL:

create database `test`character set utf8 collate utf8_general_ci;
create table `test`.`testtable`( `id` int ); 

PHP:

<?php
$link = new \PDO('mysql:host=localhost;dbname=test', 'username', 'password');

//Run one of the 4 $handle assignments at a time (comment out all but one). 
//Run #4 on an empty table to compare the results of #1 and #4.

//WORKS: INSERT, followed by SELECT, followed UPDATE
//Output: 
//Rowset 1
//Rowset 2
//Results detected
$handle = $link->prepare(' insert into testtable(id) values(1);
                           select * from testtable where id = ?;
                           update testtable set id = 2 where id = ?;');


//WORKS: SELECT, followed by UPDATE
//Output: 
//Rowset 1
//Results detected
$handle = $link->prepare('select * from testtable where id = ?; 
                          update testtable set id = 2 where id = ?;');

//WORKS: UPDATE, followed by SELECT
//Output: 
//Rowset 1
//Rowset 2
//Results detected
$handle = $link->prepare('select * from testtable where id = ?; 
                         update testtable set id = 2 where id = ?;');


//DOESN'T WORK: INSERT, followed by UPDATE, followed by SELECT
//Output: 
//Rowset 1
//Expected output: same as examples 1 and 3
$handle = $link->prepare('insert into testtable(id) values(1);
                          update testtable set id = 2 where id = ?;
                          select * from testtable where id = ?;');

$handle->bindValue('1', '1');
$handle->bindValue('2', '2');

$handle->execute();

$i = 1;
do{
    print('Rowset ' . $i++ . "\n");
    if($handle->columnCount() > 0)
     print("Results detected\n");
}while($handle->nextRowset());
?>

Does anyone have any idea as to what I’m doing wrong? Why can’t I put my select statement at the end?

PHP 5.3.5

MySQL 5.1.54

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:28:10+00:00Added an answer on May 30, 2026 at 6:28 pm

    I submitted a PHP bug report about this problem and a possible patch has been submitted. So it looks like this was a PHP bug.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran to this problem hard, it seems impossible to render. How can one
All, I ran into this problem where for a UITextField that has secureTextEntry=YES, I
I ran into this problem in a Visual Basic program that uses WMI but
I ran into a strange problem these days. One of my apps which is
One of my users is having this weird problem that I cannot seem to
This one really has me stumped. I have not ran across this problem on
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I ran into this problem and I cant solve it. Basically Im making an
I ran into this concurrency problem which I've been scratching my head for several
I ran into a problem with some C code like this: struct SomeType {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.