Re: MySql connect / broken?
| From: | Robin Ericsson | Date: | Mon, 15 Sep 2003 12:37:03 +0000 |
| Subject: | Re: MySql connect / broken? | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-21504@lists.php.net to get a copy of this message | ||
On Mon, 2003-09-15 at 13:11, richard quinn wrote:
> 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..
You should direct this question to pear-general really, as this is a
problem on your side :)
Using dsn there is no problem connecting to mysql without password like
this:
mysql://root@localhost/database
hth
Robin