|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49280 ext/mysqlnd: Not possible to detect mysqlnd in php
Submitted: 2009-08-17 14:10 UTC Modified: 2011-01-06 16:07 UTC
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: ar at ez dot no Assigned: mysql (profile)
Status: Wont fix Package: MySQLi related
PHP Version: 5.3.0 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ar at ez dot no
New email:
PHP Version: OS:


 [2009-08-17 14:10 UTC] ar at ez dot no
There doesn't seem to be possible to cleanly* detect that mysqlnd is currently in use.

* Constant would be nice, preferably already in
Detecting by presence off 'mysqli_fetch_all' or other functions is not exactly clean.

Use case: Disabling / enabling Persistent Connections based on application specific settings.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-17 14:21 UTC] ar at ez dot no
Seems to be possible with something like this as well:

strpos( mysqli_get_client_info(), 'mysqlnd ' ) !== false

But constant would still be a bit cleaner.
 [2009-08-17 14:30 UTC]
So you want to circumvent a bug by adding a constant instead of fixing the actual bug? Can you please explain WHAT does not work like it should when you have enabled mysqlnd..?
 [2009-08-17 14:53 UTC] ar at ez dot no
Hi jani!

I'm not trying to workaround anything, its just that Persistent Connections are only supported on mysqli when mysqlnd is used.

So it doesn't help to detect php version using PHP_VERSION, as the end user might have mysqlnd disabled / not compiled in.

It is possible to detect it by by using function_exists. But since you guys might add those extra mysqlnd functions to the other mysql driver as well, that is not reliable not to mention clean.

For what I'm trying to do:
eZ Publish like other php projects abstracts things, one of those is Persistent connection, witch is abstracted into a ini setting (changeable in admin gui). So I need to prepend "p:" IF user has mysqlnd, or trow a warning about unsupported setting.
 [2009-08-17 17:18 UTC]
"p:" is allowed always since PHP 5.3.0. You only get a warning when someone has disabled persistent connections with mysqli.allow_persistent ini option. You don't need to know whether it's mysqlnd or libmysql that is used. And you really should be checking if mysql*.allow_persistent is on or off anyway. :)

 [2009-08-17 17:28 UTC] ar at ez dot no
> And you really should be checking if mysql*.allow_persistent is
on or off anyway

We don't need hide php warnings, so if php trows a understandable warning in such a case, then that would be sufficient.

So, for my use case this is not valid anymore then, Thanks;)

But as long as mysqlnd behaves differently then the old mysql client, I would vote for such a constant anyway. Or you can close with reference to the first comment(2:21) on how to detect mysqlnd if you absolutely need to know about it in code.
 [2010-11-24 15:00 UTC]
-Package: Feature/Change Request +Package: MySQLi related
 [2011-01-06 14:42 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: mysql
 [2011-01-06 14:42 UTC]
Original issue was "bogus" (persistent connections). 

Too few relevant differences between mysqlnd and libmysql otherwise and none that you can't easily detect by e.g. using mysqli->client_info. No need for an extra constant.
 [2011-01-06 15:21 UTC]
It could still be useful and won't hurt to have it.
 [2011-01-06 15:52 UTC]
Not needed, pollution.

mysqli has client info, mysql has mysql_get_client_info(). With the mysql[i] extensions the info which library is used can be retrieved with a simple stristr() call using the API that is there to tell you the client [library] version [string]: *_client_info(). Even stinky PDO has a version string, although documented as int: PDO::ATTR_CLIENT_VERSION.
 [2011-01-06 15:55 UTC]
That's not pollution. We already had mysqlnd specific bugs or cases where we would 
have liked to detect at runtime which backend is used. That's a rather common 
 [2011-01-06 16:07 UTC]
How to detect the client library in use is described below: use the existing API.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Mar 30 21:03:39 2023 UTC