dsnw2651 2013-08-24 14:38
浏览 28

Zend Framework 2 phpcloud数据库

I am taking the Zend Framework 2 Skeleton tutorial but have elected to use the mysql database in my container at my.phpcloud.com.

In the global.php file I have:

return array(
'db' => array(
    'driver'         => 'Pdo',
    'dsn'            => 'mysql:dbname=mycontainer;host=mycontainer-db.my.phpcloud.com',
    'driver_options' => array(
        PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
    ),
),
'service_manager' => array(
    'factories' => array(
        'Zend\Db\Adapter\Adapter'
                => 'Zend\Db\Adapter\AdapterServiceFactory',
    ),
),
);

In my local.php file I have:

return array(
'db' => array(
    'username' => 'mycontainer',
    'password' => 'mypassword',
),

);

I receive no errors, even if I purposely put in incorrect credentials. My view loads properly...except that there are no records. I've verified that the table exists and it is named correctly. I've verified that the table contains records.

If I return the Controller to call an array for the view, rather than a populated ViewModel, it loads the view with errors, as expected, since the AlbumTable does not load. In other words, the View is being routed correctly. It just seems like the database is returning no results. I've copied and pasted everything to the correct files and triple checked it all. I completed this tutorial locally with Zend Server and MySql and it runs perfectly. It's just the PHPCloud, which issues no errors, that seems to be returning no records from its database, whether I purposely introduce bad credentials or not.

Thanks for any assistance in advance.

  • 写回答

1条回答 默认 最新

  • doulian8554 2014-01-05 15:02
    关注

    Try something like this:

    $dsn = sprintf(
        'mysql:dbname=%s;host=%s',
        get_cfg_var('zend_developer_cloud.db.name'),
        get_cfg_var('zend_developer_cloud.db.host')
    );
    
    return array(
        'db' => array(
            'driver'     => 'pdo',
            'dsn'       => $dsn,
            'username'  => 'mycontainer',
            'password'  => 'mypassword',
         ),
    );   
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀