1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MySQLi stmt - Commands out of sync

Discussion in 'MySQL' started by ideas_man, Apr 17, 2007.

  1. #1
    I recently started using the mysqli extension out of curiosity more than anything, but I seem to have hit a brick wall.

    A common task for me is to perform actions on rows returned by a query.By this I mean that would perform queries whilst looping through the results of a previous query.

    However, while I am looping through the results of the first query, I am unable to perform any other queries and keep looping with mysqli.For example.

    
    $stmt->prepare(**SQL STATEMENT**);
    $stmt->bind_param(**PARAMETERS**);
    $stmt->execute();
    $stmt->bind_result(**RESULT VARS**);
    
    
    while($stmt->fetch()){
    
      //Perform another prepared statement to UPDATE a row fails here
    
    
    }
    
    Code (markup):
    I can overwrite the prepared statement but after the first iteration of the while loop, the loop exits because the result set has gone.

    I can't create a new stmt (eg $stmt2) because that generates the following error:

    
    Commands out of sync; you can't run this command now.
    
    Code (markup):
    Does anyone know how I can still run prepared statements whilst looping through an existing result set?Looping through results with standard mysql and performing additional queries is simple enough but I'm not sure that I am missing with mysqli.

    Any help would be appreciated.Thanks :)
     
    ideas_man, Apr 17, 2007 IP
  2. Scolls

    Scolls Guest

    Messages:
    70
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0