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

  • Home
  • SEARCH
  • 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 893787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:16:36+00:00 2026-05-15T14:16:36+00:00

what if I want to update data via prepared stmt each query loop, but

  • 0

what if I want to update data via prepared stmt each query loop, but why fails. the error msg is “All data must be fetched before a new statement prepare takes place “

$link = mysqli_connect("localhost", "admin", "", "test");

if (!$link) {
    die('Connect Error: ' . mysqli_connect_error());
}

//field_1 is PK

if ($stmt = mysqli_prepare($link, "SELECT field_1, field_2 FROM table_data")) {
    mysqli_stmt_execute($stmt);    
    mysqli_stmt_bind_result($stmt, $col1, $col2);    

    while (mysqli_stmt_fetch($stmt)) {    
    $updateC= "update table_data set  field_3=? where field_1=?"    

    if ($stmt2= mysqli_prepare($link, $updateC)) {
        mysqli_stmt_execute($stmt2);
        $status='test'; //get return value from function            
        mysqli_stmt_bind_param($stmt2, 'ss', $status, $col1);
    }
  mysqli_stmt_close($stmt2);
 }


    mysqli_stmt_close($stmt);
}


mysqli_close($link);
  • 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-15T14:16:36+00:00Added an answer on May 15, 2026 at 2:16 pm

    You are preparing a second statement within a loop which is retrieving data from the first statement. You might be able to solve this by creating two connections. See this post:

    http://osdir.com/ml/php.zend.framework.db/2007-07/msg00027.html

    You might also be able to read all the rows from the first query into an array, and then loop over the array, placing your second query in that loop.

    It may be possible (and I haven’t tried this), to prepare the second statement in advance. When in the loop, bind the variables to it and execute it. Something like this (completely untested!):

    $stmt1 = mysqli_prepare($link, "SELECT field_1, field_2 FROM table_data");
    $stmt2= mysqli_prepare($link, "update table_data set  field_3=? where field_1=?");
    
    if ($stmt1 && $stmt2) {
        mysqli_stmt_execute($stmt1);    
        mysqli_stmt_bind_result($stmt1, $col1, $col2);
    
        while (mysqli_stmt_fetch($stmt)) {
            $status='test'; //get return value from function 
            mysqli_stmt_bind_param($stmt2, 'ss', $status, $col1);
            mysqli_stmt_execute($stmt2);
        }
    
        mysqli_stmt_close($stmt2);
        mysqli_stmt_close($stmt1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My customer doesn't want a database but would prefer to update their data in
I want to update data via web service in Android. performing POST operation for
I understand how to update active user data via using a form... But how
What I want: Update all new commits from server with my local repository in
i want to update my sqlite database but i cannot find the way to
I have developed a windows forms c# application, i just want update items in
I want to update some file in a server, with an automated script and
I want to update a column in a table making a join on other
I want to update a .class file in a jar with a new one.
I want to update an ASP .NET web application (including web.config file changes and

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.