4
Consider the following adaptor class DbAdapterMySQL
that extends the class PDO
:
class DbAdapterMySQL extends \PDO implements DbInterface
{
public function __construct(array $config)
{
$dsn = "mysql:dbname={$config['dbname']};host={$config['host']}";
//A próxima linha é a 13
parent::__construct($dsn, $config['username'], $config['passwd']);
}
//...
}
Note that for the constructor method an array is passed with the database access settings with the following structure:
db = MySQL
dbname = teste
username = 'root'
passwd = 'root'
host = 127.0.0.1
So far everything works perfectly, but if you replace the value of the index host
for localhost
the following error is returned:
Fatal error: Uncaught Exception 'Pdoexception' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /home/Filipe/Projects/teste/lib/vendor/Testes/Db/Adapter/Dbadaptermysql.php:13 Stack trace: #0 in /home/Filipe/Projects/teste/lib/vendor/Testes/Db/Adapter/Dbadaptermysql.php on line 13
Why error occurs when using the localhost
?
Using linux or mac?
– rray
@rray linux, I’ll add the tag.
– Filipe Moraes
That seems to be in the solution of the problem, pq well it is strange to try to connect in the bank and receive an Exception saying file not found.
– rray
@rray was the problem. The first part of the answer is enough to change the
php.ini
. Do you want to post the answer or do I?– Filipe Moraes
I have no way to test, create a response with the details :), just cite the link.
– rray