[RFC] Add fetch_column method to mysqli

php.internals

Kamil Tekiela

5 years ago
Hi Internals, I have written a new proposal in the series of improvements to mysqli extension. This one aims to add a new method mysqli_result::fetch_column as well as its functional counterpart. https://wiki.php.net/rfc/mysqli_fetch_column The RFC is very simple, but I am looking for your opinions. I also have doubts about the scope. Is the scope too limited? Should it involve a change to fetch_all as well? On the implementation part, I wonder if it could be optimized. The one I have written works but doesn't look like the most efficient way to do this. Kind Regards, Kamil Tekiela

Kamil Tekiela

5 years ago
I am bumping this thread. I assume that it got lost a little bit with was going on over the past week. I have implemented changes to fetch_all by adding two new constants and another optional parameter. This is only MVP. Both changes can be seen together here https://github.com/php/php-src/compare/master...kamil-tekiela:mysqli-fetch_all-column Is this something that people would want to see implemented in mysqli? Should the RFC be amended to include fetch_all() as well?

Nikita Popov

5 years ago
On Sun, Mar 28, 2021 at 6:00 PM Kamil Tekiela <tekiela246@gmail.com> wrote:
> Hi Internals, > > I have written a new proposal in the series of improvements to mysqli > extension. This one aims to add a new method mysqli_result::fetch_column as > well as its functional counterpart. > > https://wiki.php.net/rfc/mysqli_fetch_column > > The RFC is very simple, but I am looking for your opinions. I also have > doubts about the scope. Is the scope too limited? Should it involve a > change to fetch_all as well? > > On the implementation part, I wonder if it could be optimized. The one I > have written works but doesn't look like the most efficient way to do this. >
Looks like a reasonable addition to me. The implementation can be optimized if mysqlnd is used. It's possible to call mysqlnd_fetch_row_zval(), which will return the row in a flat zval buffer, and then pick out the one result you want and destroy the rest. You can find a sample usage in ext/mysql: https://github.com/php/pecl-database-mysql/blob/ca514c4dfacd7f1495d2fe142101fe3d91494d12/php_mysql.c#L2103-L2112 Not sure about fetch_all() support. I think the primary use case here is the case where you expect exactly one result (or zero/one results) and just need the one fetch_column() call. If you have multiple results you should be iterating the result set, not calling fetch_all()... Regards, Nikita

Kamil Tekiela

5 years ago
Hi Nikita,
>The implementation can be optimized if mysqlnd is used.
Thanks for the suggestion. I tried it but I only see ~1% performance improvement. I don't think it's worth it. I see that there is not much interest, so I will keep the RFC simple and without fetch_all() changes. I will start voting on this RFC soon if there are no more comments. Regards, Kamil