duanlei5339 2014-08-30 18:18
浏览 103
已采纳

Cakephp内联的错误消息 - 缺少数据库连接

I have done my website normally in localhost with wamp, and it came the moment to upload it inline.

I've used Cakephp 2, with the security component that block all the website. So I have to login me, before to go directly in the application. I've uploaded my data base into phpmyadmin on my web server (OVH - Perso offer, so no ssh available). I've configured the database.php file with my database informations. It is well those one, I'm sure, because it's the same like my main website (because this application is into a folder at the root of my site itself developed with Cakephp).

At a glance, when I try to access to my site, I've this error message, and I don't know why .. :

Missing Database Connection
Error: A Database connection using "Mysql" was missing or unable to connect.    
The database server returned this error: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2)

Notice: If you want to customize this error message, create app/View/Errors/missing_connection.ctp

Stack Trace
CORE/Cake/Model/Datasource/DboSource.php line 260 → Mysql->connect()
CORE/Cake/Model/ConnectionManager.php line 105 → DboSource->__construct(array)
CORE/Cake/Model/Model.php line 3482 → ConnectionManager::getDataSource(string)
CORE/Cake/Model/Model.php line 1128 → Model->setDataSource(string)
CORE/Cake/Model/Model.php line 3504 → Model->setSource(string)
CORE/Cake/Model/Model.php line 1357 → Model->getDataSource()
CORE/Cake/View/Helper/FormHelper.php line 215 → Model->schema()
CORE/Cake/View/Helper/FormHelper.php line 468 → FormHelper->_introspectModel(string, string)
APP/View/Layouts/login.ctp line 30 → FormHelper->create(string)
CORE/Cake/View/View.php line 948 → include(string)
CORE/Cake/View/View.php line 910 → View->_evaluate(string, array)
CORE/Cake/View/View.php line 542 → View->_render(string)
CORE/Cake/View/View.php line 479 → View->renderLayout(string, string)
CORE/Cake/Controller/Controller.php line 954 → View->render(null, null)
CORE/Cake/Routing/Dispatcher.php line 198 → Controller->render()
CORE/Cake/Routing/Dispatcher.php line 165 → Dispatcher->_invoke(UsersController, CakeRequest)
APP/webroot/index.php line 108 → Dispatcher->dispatch(CakeRequest, CakeResponse)

My database.php file :

class DATABASE_CONFIG {

  public $default = array(
      'datasource' => 'Database/Mysql',
      'persistent' => false,
      'host' => 'localhost',
      'login' => 'root',
      'password' => '',
      'database' => 'prolity',
      'prefix' => '',
      //'encoding' => 'utf8',
  );

  public $ovh = array(
      'datasource' => 'Database/Mysql',
      'persistent' => false,
      'host' => '***',
      'login' => '***',
      'password' => '***',
      'database' => '***',
      'prefix' => '',
      'encoding' => 'utf8',
  );
}

I use just $ovh, and it's well selected in bootstrap.php. I even tried to put

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock'

But it's the same thing.

I have all audited, and all seems correct. Google didn't help me really well, and I'm turning to you because I don't have any other ideas.

I can give you the link inline, but I think it's not really necessary.

Thanks for you're help,

Etix.

  • 写回答

2条回答 默认 最新

  • dongzai3139 2014-09-03 12:49
    关注

    The problem was that the declaration to use another database was not in the correct place. The OP was using this line in bootstrap.php

    Cache::config('default', array('engine' => 'File'));
    

    to try to change the database used. That line is used for cache files, so it has no power over database settings. To tell the models to use another database (other than default), you need to change the model attribute and do

    class Example extends AppModel {
        public $useDbConfig = 'ovh';
    }
    

    That just applies for one model, but if you want to do it for the whole app, you can add that line to AppModel

    class AppModel extends Model{
        public $useDbConfig = 'ovh';
    }
    

    (and of course, not overwrite it in the other models).

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的