php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63884 Add fetching methods
Submitted: 2013-01-02 13:04 UTC Modified: 2023-01-10 17:17 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: vincent at lycoops dot be Assigned:
Status: Wont fix Package: MySQLi related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
38 + 17 = ?
Subscribe to this entry?

 
 [2013-01-02 13:04 UTC] vincent at lycoops dot be
Description:
------------
I think it'd be great if there were a method like PDO's PDOStatement::fetch($fetch_style) method for mysqli_statement. Passing variables by reference is not always easy, espacially if you don't know how many fields are being selected or if you want to manipulate some fields. 

I (and a lot of people) use PDO only because mysqli is missing this feature, which exists in PDOStatement and mysqli_result.


I think the best way would be the following to be compatible with mysqli_result:
$statement->fetch_array(MYSQLI_ASSOC); (and all the other fetching methods)

Best regards
Vincent


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-07 12:03 UTC] cmb@php.net
Where is the problem with calling $statement->get_result(), and
fetch from the result set?

Ah, I see, this method is only implemented for mysqlnd.
 [2023-01-10 15:53 UTC] dharman@php.net
-Status: Open +Status: Wont fix
 [2023-01-10 15:53 UTC] dharman@php.net
This is a very reasonable suggestion. It would make sense to have functions like this, which is precisely why it was added in PDO. But this is mysqli... It wasn't designed to be easy to use. It was designed to be as simple (from dev pov) as possible. It was also meant to be a thin veil over the MySQL API. 

Thanks to mysqlnd, we were able to add some extra features. In PHP 8.2 we have a new method execute_query() that returns mysqli_result. We also stopped supporting libmysql which was a major limiting factor. You can rely on get_result being always present. With these improvements, I don't think this proposal is needed anymore. 

You really should consider making a permanent switch to PDO as this is the true replacement for mysql_* API. The mysqli extension has been improved enough that it can still be used in old projects, but new projects shouldn't be using it anymore. PDO offers more functionality and is much easier to use. 

If you think mysqli would benefit from this proposal nonetheless, please follow the RFC process. This enhancement can be discussed on the mailing list.
 [2023-01-10 17:17 UTC] vincent at lycoops dot be
I made this request 10 years ago...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC