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

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题