ZF2-456: PDO_Mysql Can't Connect
First off, using the PDO Driver with localhost as the hostname works great! However, remote hosts cannot connect.
Here is the non working PDO example:
'db' => array( 'driver' => 'Pdo', 'dsn' => 'mysql:dbname=dbnamehere;hostname=hostnamehere', 'username' => 'username', 'password' => 'password', 'driver_options' => array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' ), ),
The error I am receiving is:
/usr/local/apache/vhosts/otwebsoft_admin/vendor/Zend/Db/Adapter/Driver/Pdo/Connection.php:246 Connect Error: SQLSTATE[HY000]  No such file or directory
If I install the mySQL Server/Database on the same machine and use localhost as the hostname, everything is OK. Using a remote host fails.
As a test I setup PDO the old fashioned way to ensure that connections were being used properly:
Here is the working example:
$dsn = 'mysql:host=hostnamehere;dbname=databasename'; $username = 'username'; $password = 'password'; $options = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8', ); $dbh = new PDO($dsn, $username, $password, $options); $stmt = $dbh->prepare('select * from passport'); $stmt->execute(); print_r($stmt->fetch());
When I use the above code to access a remote database I am returning the expect results.
As an additional test I reset a sandbox and installed only the ZF2 Tutorial based on Akrabat's examples.
For the time being I've switched my DB Params over to Mysqli and it's working just fine connecting to my remote server but of course I'd much rather use PDO.
Yes, I have tried with both an actual hostname, ipv4, and ipv6 address. All the same results.