Overwrite the bind_* variables with data from the arrray $stmt->bindParam(':usrid', $_SESSION, PDO::PARAM_INT) $stmt->bindParam(':address1', $bind_address1, PDO::PARAM_STR) $stmt->bindParam(':surname', $bind_surname, PDO::PARAM_STR) $stmt->bindParam(':firstname', $bind_firstname, PDO::PARAM_STR) As such you only need to call bindParam once outside your loop, then within your loop just overwrite the variable with the data. I do not understand how you can move the bind statements outside the foreach $data statement and expect anything to work, how does the data get to the record if the bind does not happen inside the foreach? Am I missing something here or is my understanding of this wrong?bindParam accepts a variable by reference.
#Php pdo fetchall full
My Catch statement in full which is immediately after the try block is: I do understand that somewhere something must be failing but I do not see how the rollback is happening without the error being reported as the only rollback statement present is within the catch statement which outputs the error to the screen and a text file before the rollback can be initiated. I do not understand how you can move the bind statements outside the foreach $data statement and expect anything to work, how does the data get to the record if the bind does not happen inside the foreach? Am I missing something here or is my understanding of this wrong? I have this problem with or without the rollback being present. I have the prepare, bind and execute inside the " try" statement with a " catch" immediately after it which has an echo to the screen that an error has occurred, it also outputs the error to a text file before issuing the rollback. It maybe my lack of understanding with PHP & PDO but I thought that any failure within the " try" statement would be reported by the " catch" statement which immediately follows it?
#Php pdo fetchall update
Insert or update using $data, $data, etc When submitting the data you can just loop the records to save the details: Setup your form using a similar array structure so it's easy to handle when submitting changes. You can check if there is one or two contacts by using count($records). $records would be your first contact, $records would be your second (if it exists). $records = $stmt->fetchAll(PDO::FETCH_ASSOC) Use arrays, and rather than using a bunch of separate arrays, just use a single array called $records or similar. Separating things out into a bunch of separate variables is probably the least efficient way of handling it though. There are numerous ways such a task could be accomplished. If i do a fetch with a while loop or a fetchAll with a foreach loop the only way I can think of making this work is for the variables ($myfisrtname, $mysurname etc) to be arrays themselves?
This data is not just displayed on the screen it is amendable by the user and when the user presses the update button if any fields have been modified I have to be able to put the data which is on the screen back in to the carer file records. The user must have at least 1 of these filled in and the other can be blank, but at any stage the user is allowed to amend either set of details, which is why I believed they had to be referenced with 2 sets of variables.
The system I am working on displays a screen with 2 Name & Address details side by side.
#Php pdo fetchall how to
This will have the same out come as the while loopĬh0cu3r, Obviously this is my misunderstanding of how the fetchAll works, I assumed that both records would be returned but held in an array which would be accessible in some way to assign the $myfirstname=firstname & $myfirstname2=firstname and this is the part I did not understand how to do.
If you used fetchAll you still need to use some form of loop,įoreach($stmt->fetchALL(PDO::FETCH_ASSOC) as $row) This will loop over the results displaying the information for each user. displayes the name, address and town for each record in the resultĪddress: $myadddress1$myaddress2$myaddress3 While($row = $stmt->fetch(PDO::FETCH_ASSOC))
#Php pdo fetchall code
Your code for displaying the record needs to go into the while loop with the variables. This is the method you need to do in order loop over the results returned form a query.