note 115320 added to pdo.construct
| From: | kthari85 at gmail dot com | Date: | Fri, 04 Jul 2014 11:26:28 +0000 |
| Subject: | note 115320 added to pdo.construct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199849@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 103.241.147.77
Probable Submitter: 116.68.99.73
----
Manual Page -- http://php.net/manual/en/pdo.construct.php
Edit -- https://master.php.net/note/edit/115320
Del: integrated -- https://master.php.net/note/delete/115320/integrated
Del: useless -- https://master.php.net/note/delete/115320/useless
Del: bad code -- https://master.php.net/note/delete/115320/bad+code
Del: spam -- https://master.php.net/note/delete/115320/spam
Del: non-english -- https://master.php.net/note/delete/115320/non-english
Del: in docs -- https://master.php.net/note/delete/115320/in+docs
Del: other reasons-- https://master.php.net/note/delete/115320
Reject -- https://master.php.net/note/reject/115320
Search -- https://master.php.net/manage/user-notes.php