MySql connect / broken?

From: Date: Mon, 15 Sep 2003 11:11:07 +0000
Subject: MySql connect / broken?
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-21503@lists.php.net to get a copy of this message
Hi, I have had a 3 year break from PHP, but have just started up again. Of course the first task was to get PEAR working, it seems a big improvement over PHP-Lib. Except: My default MySQL installation is root / <empty password>, but the MYSQL::Connect can't cope with this. In particular, from lines 122 in mysql.php: if ($dbhost && $user && $pw) { $conn = @$connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = @$connect_function($dbhost, $user); } elseif ($dbhost) { $conn = @$connect_function($dbhost); } else { $conn = false; } So I connect with $dbhost = 'localhost'; $user = root; $pass = ''; The code above goes to the first else condition: $conn = @$connect_function($dbhost, $user); And Mysql returns an error saying that the password is incorrect, since it should be ''. My quickfix: if ($dbhost && $user && $pw) { $conn = @$connect_function($dbhost, $user, $pw); } elseif ($dbhost && $user) { $conn = @$connect_function($dbhost, $user, $pw); if (empty($conn)) { $conn = @$connect_function($dbhost, $user); } } elseif ($dbhost) { $conn = @$connect_function($dbhost); } else { $conn = false; } Seems to fix the problem. If no $pw is empty, I still try to connect with it. If it doesn't work: i.e. MySQL does not want to see an empty password, then we just try again. But an improvement over the current DSN parsing schema would surely be to add a connection_info class? Attributes: user, pw, host, db. The ::connect functions could recieve the connection_info class and be informed whether a value is nonexistent or set to an empty string... Just some thoughts, I hope I chose the correct list here.. Richard

« previous php.pear.dev (#21503) next »