php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64032 mysqli reports different client_version with procedural and object style
Submitted: 2013-01-20 23:43 UTC Modified: 2020-02-27 08:42 UTC
From: shakaran at gmail dot com Assigned: cmb (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.21 OS: Centos 5.9
Private report: No CVE-ID: None
 [2013-01-20 23:43 UTC] shakaran at gmail dot com
Description:
------------
I am using a Centos 5.9 server with cPanel and Php 5.3.15 with MySQL 5.5.28. 
When I try to get the current mysql version from mysqli using procedural or 
object oriented style I get slightly different version.

With object style, I get 50524 as integer, according to 
http://php.net/manual/en/mysqli.get-client-version.php that is 5.5.24 (wrong 
version). But with procedural style I get 50528 as integer, that is 5.5.28 (the 
real version).

This could be tested with the commands attached in test script section, but it 
is not always reproducible (maybe for slighly differences in system 
configuration).

I think that both methods should read the data from the same location and 
reports the exact and same version, it is weird that different values appears. 
This could be a different config in MySQL for version headers or it is getting 
older version headers from some path, but php always should get the same version 
from both methods. I only can reproduce in one system (three tested), so I am 
thinking that's a false positive from some mysql config.

Also, (I am lazy for fill another documentation bug) I detect at 
http://php.net/manual/en/mysqli.get-client-version.php that it says "Returns the 
MySQL client version as a string" and below says in description section "Returns 
client version number as an integer.". Since it return always a integer, the 
docs are wrong and should be changed to "Returns the MySQL client version as an 
integer".

Test script:
---------------
# php -r '$mysqli = new mysqli(); var_dump($mysqli->client_version); var_dump(mysqli_get_client_version());' ; mysql --version; php --version
int(50524)
int(50528)
mysql  Ver 14.14 Distrib 5.5.28, for Linux (x86_64) using readline 5.1
PHP 5.3.15 (cli) (built: Aug  9 2012 07:10:41) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
    with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
    with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH

Mysql modules present:
# php -m | grep mysql
mysql
mysqli
pdo_mysql

In another system with Centos 6.3, cPanel and PHP 5.3.20 and MySQL 5.5.28 it works nice:

php -r '$mysqli = new mysqli(); var_dump($mysqli->client_version); var_dump(mysqli_get_client_version());' ; mysql --version; php --version
int(50528)
int(50528)
mysql  Ver 14.14 Distrib 5.5.28, for Linux (x86_64) using readline 5.1
PHP 5.3.20 (cli) (built: Jan 21 2013 00:24:03) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube Ltd., and
    with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
    with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH

Expected result:
----------------
Same mysql version using both methods

Actual result:
--------------
Different versions using both methods

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-21 01:37 UTC] shakaran at gmail dot com
Additionally using mysqli_init() has the same behaviour.

# php -r '$mysqli = mysqli_init(); var_dump($mysqli->client_version); 
var_dump(mysqli_get_client_version());' ; mysql --version; php --version
int(50524)
int(50528)
mysql  Ver 14.14 Distrib 5.5.28, for Linux (x86_64) using readline 5.1
PHP 5.3.15 (cli) (built: Aug  9 2012 07:10:41) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by 
eAccelerator
    with the ionCube PHP Loader v4.2.2, Copyright (c) 2002-2012, by ionCube 
Ltd., and
    with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
    with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
 [2013-01-31 21:06 UTC] shakaran at gmail dot com
From Pierre Joye's twitter suggestion I add this info. I am using libmysql (no 
mysqlnd). It is the default shipped with cPanel in CentOs with easyapache 
script.

Some additional info:

# php -i | grep mysql

Configure Command =>  './configure'  '--enable-bcmath' '--enable-calendar' '--
enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-intl' '--enable-
libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--
enable-safe-mode' '--enable-soap' '--enable-sockets' '--enable-wddx' '--enable-
zend-multibyte' '--enable-zip' '--prefix=/usr/local' '--with-
apxs2=/usr/local/apache/bin/apxs' '--with-bz2' '--with-config-file-
path=/usr/local/lib' '--with-config-file-scan-dir=/usr/local/lib/php.ini.d' '--
with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-enchant=/usr' '--with-
freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-icu-dir=/usr' '--with-
imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' 
'--with-kerberos' '--with-libdir=lib64' '--with-libexpat-dir=/usr' '--with-
libxml-dir=/opt/xml2' '--with-libxml-dir=/opt/xml2/' '--with-
mcrypt=/opt/libmcrypt/' '--with-mm=/opt/mm/' '--with-mysql=/usr' '--with-mysql-
sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-
openssl=/usr' '--with-openssl-dir=/usr' '--with-pcre-regex=/opt/pcre' '--with-
pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pic' '--with-png-dir=/usr' 
'--with-pspell' '--with-sqlite=shared' '--with-tidy=/opt/tidy/' '--with-xmlrpc' 
'--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-
dir=/usr'
mysql
MYSQL_SOCKET => /var/lib/mysql/mysql.sock
MYSQL_INCLUDE => -I/usr/include/mysql
MYSQL_LIBS => -L/usr/lib64 -lmysqlclient 
mysql.allow_local_infile => On => On
mysql.allow_persistent => On => On
mysql.connect_timeout => 60 => 60
mysql.default_host => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
mysql.default_user => no value => no value
mysql.max_links => Unlimited => Unlimited
mysql.max_persistent => Unlimited => Unlimited
mysql.trace_mode => Off => Off
mysqli
MYSQLI_SOCKET => /var/lib/mysql/mysql.sock
mysqli.allow_local_infile => On => On
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_pw => no value => no value
mysqli.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
mysqli.default_user => no value => no value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.reconnect => Off => Off
PDO drivers => sqlite, sqlite2, mysql
pdo_mysql
pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => 
/var/lib/mysql/mysql.sock

# ldd /usr/local/lib/php/extensions/no-debug-non-zts-20090626/pdo_mysql.so
	linux-vdso.so.1 =>  (0x00007fffb9d03000)
	libmysqlclient.so.18 => /usr/lib64/libmysqlclient.so.18 
(0x00002ac356f05000)
	libm.so.6 => /lib64/libm.so.6 (0x00002ac357469000)
	librt.so.1 => /lib64/librt.so.1 (0x00002ac3576ed000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00002ac3578f6000)
	libc.so.6 => /lib64/libc.so.6 (0x00002ac357afa000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00002ac357e54000)
	/lib64/ld-linux-x86-64.so.2 (0x00000030ed200000)
 [2013-03-13 13:06 UTC] uw@php.net
Good find, must be a bug dating back years:

 OO interfaces uses compile time MYSQLI_VERSION
 Procedural interfaces uses run time C API function call

However, its slightly in the grey area. Client library version and server version are expected to match in general. AFAIK, in the past, only very conservative statements have been made about using library versions that differ from server version, particularily if using old library to connect to new server - which seems to be your case.
 [2013-03-13 13:06 UTC] uw@php.net
-Status: Open +Status: Verified
 [2013-03-13 13:07 UTC] uw@php.net
s/MYSQLI_VERSION/MYSQL_VERSION_ID
 [2013-03-13 16:24 UTC] shakaran at gmail dot com
ext/mysqli/php_mysqli_structs.h:91:#define MYSQLI_VERSION_ID		101009
ext/mysqlnd/mysqlnd.h:26:#define MYSQLND_VERSION_ID 50011
ext/mysqlnd/mysqlnd_libmysql_compat.h:36:#define MYSQL_VERSION_ID		
MYSQLND_VERSION_ID
 [2017-04-02 14:45 UTC] tpunt@php.net
-Package: mysql +Package: MySQLi related
 [2020-02-26 17:43 UTC] cmb@php.net
To clarify, this has nothing to do with the server (version); it's
rather about the difference of the version PHP (or the respective
extension) has been built against vs. which version is availble
during runtime.
 [2020-02-26 17:44 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #64032: mysqli reports different client_version
On GitHub:  https://github.com/php/php-src/pull/5213
Patch:      https://github.com/php/php-src/pull/5213.patch
 [2020-02-27 08:41 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8654c32b584d448cbf9f341693b227db193fe155
Log: Fix #64032: mysqli reports different client_version
 [2020-02-27 08:41 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2020-02-27 08:42 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC