note 115320 rejected from pdo.construct by salathe
| From: | salathe@php.net | Date: | Fri, 04 Jul 2014 11:33:36 +0000 |
| Subject: | note 115320 rejected from pdo.construct by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199850@lists.php.net to get a copy of this message | ||
Note Submitter: kthari85 at gmail dot com
----
The parameter name is passwd , and not password.
<?php
public PDO::__construct ( string $dsn [, string $username [, string $passwd [, array $options ]]] )
?>
When you are using a dependency injection container which uses Reflection internally and when using
the string password then it will never get connected throwing error unable to connected with no
password.
Eg : taken from Aura.Di
<?php
$di->params['PDO'] = array(
'dsn' => 'mysql:dbname=dbname;host=127.0.0.1',
'username' => 'username',
'passwd' => 'somep'
);
$pdo = $di->newInstance('PDO');
?>
Wrong usage given belwo. Note the difference in passwd and password
<?php
$di->params['PDO'] = array(
'dsn' => 'mysql:dbname=dbname;host=127.0.0.1',
'username' => 'username',
'password' => 'somep'
);
$pdo = $di->newInstance('PDO');
?>
I hope this will help someone not to spend hours of debugging and trying refelection to see which
paramter name is for the constructor.