1

I have 2 prepared statements in function. After I get result from first, I need one field's value from this result to be used in second statement as bind_param() function's parameter. But I was getting error, until I found out about store_result() function and used it after first statement. So can you tell or give some reference to read, why is there need to use store_result() function and why this problem arises, during using 2 prepared statements.

I don't know if I am right, but in my opinion this happens because I am not closing first statement before starting second and maybe because of both are open, some error arises.

EDIT:
I found out some information, that somehow helps me to solve this problem

Command out of sync:

This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.

David Demetradze
  • 1,361
  • 2
  • 12
  • 18

1 Answers1

1

store_result() it self for using Transfers a result set from the last query.

Example :
$stmt = $mysqli->prepare("SELECT col1,col2 FROM tabel WHERE col1= ?")
$stmt->bind_param('s', $test);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($col1,$col2);
$stmt->fetch();
  1. You can read it in here how to use prepared-statement.
  2. You can read this documentation how to use mysqli prepared-statement.
Community
  • 1
  • 1
Eko Junaidi Salam
  • 1,663
  • 1
  • 18
  • 26