PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB » Bug #13

Connect broken Null PW in Mysql 4.0.15

Details

Submitted2003-09-16 07:30 UTC
Frompear at richard-quinn dot com
Assigneddanielc
StatusClosed
PackageDB
PHP Version4.3.3
OSWinXP
Roadmaps(Not assigned)

Comments

[2003-09-16 07:30 UTC] pear at richard-quinn dot com

Description:
------------
Pear::DB::Mysql::Connect does not send an empty $pw to *mysql_real_connect causing login failure.

Fix below:

Compare: (<)M:\dev\php4\PEAR\go-pear-bundle\mysql.php (27225 bytes)
with: (>)M:\dev\php4\PEAR\DB\mysql.php (26542 bytes)

123c123,126
< $conn = @$connect_function($dbhost, $user);
---
> $conn = @$connect_function($dbhost, $user, $pw);
> if (empty($conn)) {
> $conn = @$connect_function($dbhost, $user);
> }
128c131,133
< }
---
> }
>
>

Reproduce code:
---------------
You must be using Mysql v. 4. I use 4.0.15.
Create a DSN with the following code:

$user = 'root';$pass = '';$host = 'localhost';$db_name = 'mysql';
$dsn = "mysql://$user:$pw@$host/$db_name";
//echo (mysql_connect($host,$user));

Expected result:
----------------
A DB object, or more specifically a *string answer from MYSQL giving the resource ID.

Actual result:
--------------
Pear::DB say "connection failed". Closer analysis reveals MySQL saying "Password incorrect, use passwords is YES".

The root user's password on a clean install is '' <zero length string>, but PEAR::DB cannot distinguish between an unset $pw and a $pw of no bytes, since this is all parsed by the DSN parser.

So PEAR::DB sees that $pw is empty, and tries to connect without specifying the PW to *mysql_real_connect (a NULL is passed), which causes completely the wrong behaviour. MYSQL changed the NULL and EMPTY password behaviour in v. 4.

- Rich