php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67046 mysqli_stmt::free_result also clears result bindings
Submitted: 2014-04-09 03:16 UTC Modified: 2014-04-09 08:00 UTC
From: jon dot kloske at gmail dot com Assigned:
Status: Closed Package: MySQLi related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jon dot kloske at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-09 03:16 UTC] jon dot kloske at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/mysqli-stmt.free-result
---
"mysqli_stmt::free_result -- mysqli_stmt_free_result — Frees stored result memory for the given statement handle"

It also clears the result bindings, so that you need to call mysqli_stmt::bind_result again if you're going to use the prepared statement a second time after this.

In spite of the manual for bind_result saying that it must be called after execute, this doesn't appear to actually be required in all the testing I've done. Ie, if you have a prepared statement that returns a name column based off an id, you can bind $id to the id in the parameter and $name to the name result at the end before calling execute and it seems to work fine. You can then keep changing $id and calling execute and fetch and $name gets filled correctly. If you however call free_result after the fetch (ie, if you're using store_result) the next time you run execute $name isn't bound to the result.

The manual page isn't particularly clear on these unintended side effects of free_result since all it says is it frees the stored result memory, not also the bindings...


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-09 08:00 UTC] jon dot kloske at gmail dot com
-Status: Open +Status: Closed
 [2014-04-09 08:00 UTC] jon dot kloske at gmail dot com
Hrm... this might be a php windows thing, and may need multiple concurrent prepared statements on the same db connection to trigger. I just tried a simpler version and it didn't unbind the results. Maybe I should work on a repro condition first as this may actually be a bug rather than a documentation problem.
I'm going to nuke my own report until then!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC