From: tjerk dot meesters at gmail dot com
Operating system: Linux 2.6
PHP version: 5.1.6
PHP Bug Type: MySQL related
Bug description: mysql_connect() returns NULL
Description:
------------
A simple mysql_connect() returned NULL for this particular configuration
of PHP:
--with-mysql=/usr/lib/mysql
--with-mysql-sock=/var/run/mysqld/mysqld.sock
--with-mysqli=/usr/bin/mysql_config
--with-pdo-mysql=/usr
When the script is ran with wrong login credentials, mysql_connect()
returns false as documented. However, when everything checks out no errors
are thrown and NULL is returned instead of a resource.
This is not documented behaviour as far as I know ;-)
Reproduce code:
---------------
<?php
error_reporting(E_STRICT);
$r = mysql_connect('localhost','user','pw');
var_export($r);
?>
Expected result:
----------------
"Resource #1" (or something similar)
Actual result:
--------------
"NULL"
A strace on the process returns the following:
...
socket(PF_FILE, SOCK_STREAM, 0) = 3
fcntl64(3, F_SETFL, O_RDONLY) = 0
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_GETFL) = 0x2 (flags O_RDWR)
fcntl64(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
connect(3, {sa_family=AF_FILE, path="/var/run/mysqld/mysqld.sock"}, 110) =
0
fcntl64(3, F_SETFL, O_RDWR) = 0
setsockopt(3, SOL_IP, IP_TOS, [8], 4) = -1 EOPNOTSUPP (Operation not
supported)
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
poll([{fd=3, events=POLLIN, revents=POLLIN}], 1, 60000) = 1
read(3, "9\0\0\0\n5.0.24a-log\0\331\1\0\0TOlT=vZ?\0,\242"..., 16384) = 61
brk(0x8747000) = 0x8747000
stat64("/usr/share/mysql/charsets/Index.xml", {st_mode=S_IFREG|0644,
st_size=18221, ...}) = 0
open("/usr/share/mysql/charsets/Index.xml", O_RDONLY|O_LARGEFILE) = 4
read(4, "<?xml version=\'1.0\' encoding=\"ut"..., 18221) = 18221
close(4) = 0
write(3, ">[EMAIL PROTECTED]"..., 66)
= 66
read(3, "\7\0\0\2\0\0\0\2\0\0\0", 16384) = 11
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0xb7f00000
write(1, "NULL", 4NULL) = 4
close(0) = 0
An ldd on the php cli:
...
libmysqlclient.so.15 => /usr/lib/mysql/libmysqlclient.so.15
(0xb78f6000)
--
Edit bug report at http://bugs.php.net/?id=39174&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39174&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39174&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39174&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39174&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39174&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39174&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39174&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39174&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39174&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39174&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39174&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39174&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39174&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39174&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39174&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39174&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39174&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39174&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39174&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39174&r=mysqlcfg