PHP-7: #2 mysqli query returns "no results" unless #1 query is closed first
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
PHP-7: #2 mysqli query returns "no results" unless #1 query is closed first
I have a PHP routine that tries to execute two queries, one after the other, and to iterate through the result-set of both.
However, I am finding that, unless I explicitly do a "mysqli_stmt::close()" on the first statement, the second statement(s), although they appear to run, produce no results. (The "affected count," e.g. of a SELECT statement, is zero.)
$mysqli_stmt->affected_rows returns affected rows with an insert, update or delete query
$mysqli_stmt->num_rows returns rows with a select query but you may need a $mysqli_stmt->store_result() before
Goofy updates: if I close() the first statement-object (my code actually uses a "wrapper" class which encapsulates both a statement and a result handle ...), the next one runs fine.
G-o-o-f-y: If you use different PHP variables each time to store the object (returned by a static "query()" method), it also works. But, if you assign the new object to the same variable ... even though it is obviously a new and different object-instance ... it will not work.
I have an explicit destructor in the object to explicitly close and discard the mysqli objects. I can see that this destructor is running timely. It does not affect anything.
I suspect a flaw either in mysqli or, just as likely, PHP-7 itself.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.