Consider the following adapter 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']);
}
//...
}
Notice that for the constructor method an array with database access settings is passed 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% index with% with% with%, 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 does the error occur while using host
?