php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67026 PDO on Windows ignores username when password is empty and username is not root
Submitted: 2014-04-05 05:16 UTC Modified: 2014-04-05 07:35 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: unirgy at gmail dot com Assigned:
Status: Not a bug Package: PDO MySQL
PHP Version: 5.5.11 OS:
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: unirgy at gmail dot com
New email:
PHP Version: OS:

 

 [2014-04-05 05:16 UTC] unirgy at gmail dot com
Description:
------------
When trying to connect to db with a user that is not 'root' and password is empty (user has correct privileges to dbname) PDO throws exception: 

SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'mydb'

When the supplied username is 'root' and password is empty, the connect succeeds if the db user has empty password, or throws a correct exception:

SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

The issues has been reproduced on multiple installations with PHP version 5.3.8 and also Mac with MAMP 3.0.3

I wasn't sure if it's a bug and posted on SE here as well: https://stackoverflow.com/questions/22876169/pdo-on-windows-ignores-host-name-and-username-when-password-is-empty



Test script:
---------------
<?php
$host   = "localhost";
$dbname = "mydb";
$user   = "myuser";
$pass   = "";

try {
    $DBH = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $user, $pass);
} catch (Exception $e) {
    echo $e->getMessage();
}

Expected result:
----------------
Connection succeeded or exception:

SQLSTATE[HY000] [1045] Access denied for user 'myuser'@'localhost' (using password: NO)

Actual result:
--------------
SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'mydb'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-05 05:22 UTC] unirgy at gmail dot com
I see previous reports:
https://bugs.php.net/bug.php?id=43493
https://bugs.php.net/bug.php?id=46457
 [2014-04-05 06:35 UTC] unirgy at gmail dot com
I've identified that it works correctly with 'myuser'@'localhost'. The issue appears when the privileges are given to 'myuser'@'%'
 [2014-04-05 06:42 UTC] unirgy at gmail dot com
I was able to reproduce the issue on linux as well, with 'myuser'@'%' without password
 [2014-04-05 07:35 UTC] pajoye@php.net
-Status: Open +Status: Not a bug -Operating System: Windows +Operating System:
 [2014-04-05 07:35 UTC] pajoye@php.net
Definitively not a bug in php. PDO only passes the credentials over. It is also not windows specific (no windows specific code in PDO).

IIRC, it works just fine here.
 [2014-04-05 09:02 UTC] unirgy at gmail dot com
You're correct, the issue is with mysql: https://gist.github.com/sellvana/9989227
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC