duangejian6657 2017-05-03 04:43
浏览 25
已采纳

Heroku找不到PDOServiceProvider

So I followed the tutorial provided by heroku on how to deploy a php app https://devcenter.heroku.com/articles/getting-started-with-php#introduction

Everything works fine, except when I get to setting up the database. At first I tried looking for different solutions online (i.e. Dokku deployed Silex can't find PdoServiceProvider), but not seens to work.

Right now, my code looks like this:

<?php
    use Csanquer\Silex\PdoServiceProvider\Provider\PDOServiceProvider;
    //use Silex\Application;

    $dbopts = parse_url(getenv('DATABASE_URL'));
    $pdo = new PDOServiceProvider('pdo');
    //$app = new Application();
    $app->register($pdo,
        array(
            'pdo.server' => array(
                'driver'   => 'pgsql',
                'user' => $dbopts["user"],
                'password' => $dbopts["pass"],
                'host' => $dbopts["host"],
                'port' => $dbopts["port"],
                'dbname' => ltrim($dbopts["path"],'/')
            )
        )
    );
?>

And I get the following message:

Uncaught Error: Class 'Csanquer\Silex\PdoServiceProvider\Provider\PDOServiceProvider' not found in /app/web/index.php:6

How can I fix it?

  • 写回答

2条回答 默认 最新

  • doucong1992 2017-05-26 08:50
    关注

    I hope you've used composer before, if not, let me know please. Try to install Doctrine DBAL using your composer:

    composer require "doctrine/dbal:~2.5"
    

    Once you've installed Doctrine you can use the following lines of code:

    $config = new \Doctrine\DBAL\Configuration();
    
    $connParams = array(
        'driver'   => #driver -> pdo_mysql,
        'dbname'   => #dbname,
        'host'     => #host -> localhost,
        'user'     => #user,
        'password' => #password,
        'charset'  => #charset -> utf8
    );
    $conn = \Doctrine\DBAL\DriverManager::getConnection($connParams, $config);
    

    You can now use something like:

    $conn->query(#SomeSQL)
    $conn->prepare(#SomeSQL)
    

    Or in the way you like to do it:

    $app->register(new Silex\Provider\DoctrineServiceProvider(), array(
        'db.options' => array(
            'driver'   => #driver -> pdo_mysql,
            'dbname'   => #dbname,
            'host'     => #host -> localhost,
            'user'     => #user,
            'password' => #password,
            'charset'  => #charset -> utf8
        ),
    ));
    

    You can now use something like:

    $app['db']->query(#someSQL);
    

    For more information on Doctrine DBAL consult the page here or here. Please let me know whether this has helped you! (By marking the question as completed or commenting on new errors).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大