-->

Dokku deployed Silex can't find PdoServiceProv

2019-08-09 00:53发布

问题:

I have a project done with Silex, and I was using herrera-io/silex-pdo as the PDO provider, but I faced random crashes with socket errors (I connect to the DB via socket), since that lib is abandoned, I changed to csanquer/pdo-service-provider, and it works just fine on my localhost server, but when I deploy to remote, I get the following error:

PHP Fatal error: Class 'Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider' not found in /app/web/index.php on line 52

Here is the code around the line 52:

use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider;

$app->register(
// you can customize services and options prefix with the provider first argument (default = 'pdo')
    new PdoServiceProvider('pdo'), // Line 52
    array(
        'pdo.server'   => array(
            // PDO driver to use among : mysql, pgsql , oracle, mssql, sqlite, dblib
            'driver'   => 'mysql',
            'host'     => 'unix_socket=/app/mysqld.sock',
            'dbname'   => 'db_beta',
            'port'     => 3306,
            'user'     => 'user',
            'password' => 'pass',
        ),
        // optional PDO attributes used in PDO constructor 4th argument driver_options
        // some PDO attributes can be used only as PDO driver_options
        // see http://www.php.net/manual/fr/pdo.construct.php
        'pdo.options' => array(
            \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
        ),
        // optional PDO attributes set with PDO::setAttribute
        // see http://www.php.net/manual/fr/pdo.setattribute.php
        'pdo.attributes' => array(
            \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
        ),
    )
);

Thanks in advance for any help, or any clue of what may be going wrong!

回答1:

Turns out the problem was with the use instructions. To fix, simply change:

use Csanquer\Silex\PdoServiceProvider\Provider\PdoServiceProvider; To: use Csanquer\Silex\PdoServiceProvider\Provider\PDOServiceProvider;

And:

new PdoServiceProvider('pdo') To: new PDOServiceProvider('pdo')

Now it works!