1
votes

I am using ZF2 with DoctrineOrm and have recently installed a local environment using vagrant on my mac running OSX (Yasomite).

Everything works as expected except I get the following error when I attempt to use Doctrine vendor tools:

./vendor/bin/doctrine-module orm:schema-tool:create --dump-sql

The error reads:

Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in example.com/trunk/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43

EDIT

Line 43 from the offending class: parent::__construct($dsn, $user, $password, $options);

class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection
{
     public function __construct($dsn, $user = null, $password = null, array $options = null)
        {
            try {
                parent::__construct($dsn, $user, $password, $options);
                $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Doctrine\DBAL\Driver\PDOStatement', array()));
                $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            } catch (\PDOException $exception) {
                throw new PDOException($exception);
            }
        }

When I dump the variables from the catch statement, they are as expected.

I can access the mysql location via adminer: http://192.168..../adminer/

And the website loads albeit with errors as I am unable to create the DB.

I remember when I originally set up my local MAMP environment having a similar problem and had to add the following line to my pdo settings:

/Applications/MAMP/tmp/mysql/mysql.sock

 'connection' => [
            'orm_default' => [
                'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => [
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'games_cloud',
                    'password' => 'games_cloud',
                    'dbname'   => 'games_cloud',
                    'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'
                ]
            ]
        ],

I can't help but think that I need to do the same thing, however I am not really sure how to.

EDIT:

SSHing into the Vbox I see the socket is located here: /var/lib/mysql/mysql.sock

What would the correct settings be to connect to this? The following does not work:

'connection' => [
            'orm_default' => [
                'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => [
                    'host'     => '192.168.56.101/',
                    'port'     => '3306',
                    'user'     => 'games_cloud',
                    'password' => 'games_cloud',
                    'dbname'   => 'games_cloud',
                    'unix_socket' => '/var/lib/mysql/mysql.sock'   //To use Doctrine Entity Generator
                ]
            ]
        ],

Any help would be appreciated!

1
what does this line read: example.com/trunk/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43 ...what file is it trying to find and failing? Are you sure it's the unix socket?STLMikey
I have updated the question to include the method, line 43 is this: parent::__construct($dsn, $user, $password, $options);HappyCoder
in my case, the database service wasn't running after a restart. Starting it resolved it. (OS => Linux)Patrick Mutuku

1 Answers

0
votes

Managed to get this to work, it was a setting:

'connection' => [
            'orm_default' => [
                'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => [
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'games_cloud',
                    'password' => 'games_cloud',
                    'dbname'   => 'games_cloud',
                    'unix_socket' => '/var/lib/mysql/mysql.sock'
                ]
            ]
        ],