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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器