php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39174 mysql_connect() returns NULL
Submitted: 2006-10-17 12:05 UTC Modified: 2006-10-17 14:41 UTC
From: tjerk dot meesters at gmail dot com Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.1.6 OS: Linux 2.6
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tjerk dot meesters at gmail dot com
New email:
PHP Version: OS:

 

 [2006-10-17 12:05 UTC] tjerk dot meesters at gmail dot com
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, ">\0\0\1\205\242\0\0\0\0\0@!\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 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)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-17 13:11 UTC] tony2001@php.net
var_dump() is function you are looking for.
var_export() exports variables to a parsaable strings, but resources cannot be represented as strings due to their nature.
 [2006-10-17 14:34 UTC] tjerk dot meesters at gmail dot com
Argh, I can't believe how stupid that was ... mea culpa
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC