带有cakehp-inline的错误消息-缺少数据库连接


An error message with cakephp inline - Missing Database Connection

我已经用wamp在localhost中正常地完成了我的网站,现在是时候内联上传了。

我使用了Cakephp2,它带有阻止所有网站的安全组件。所以我必须登录我,然后才能直接进入应用程序。我已经将我的数据库上传到我的web服务器上的phpmyadmin中(OVH-Perso提供,所以没有ssh可用)。我已经用我的数据库信息配置了database.php文件。我敢肯定,它就是这样一个,因为它和我的主网站一样(因为这个应用程序在我的网站根目录下的一个文件夹中,它是用Cakephp开发的)。

乍一看,当我试图访问我的网站时,我收到了以下错误消息,我不知道为什么..:

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)

我的database.php文件:

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',
  );
}

我只使用$ovh,它在bootstrap.php中得到了很好的选择。我甚至试着把

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

但这是一样的。

我已经审核了所有内容,看起来都是正确的。谷歌并没有很好地帮助我,我求助于你,因为我没有任何其他想法。

我可以在线给你链接,但我认为这不是真的必要。

谢谢你的帮助,

Etix。

上传到服务器后是否更新了数据库配置?基于错误信息,我认为不是。

Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'

我真的很怀疑OVH服务器会使用XAMPP。

问题是使用另一个数据库的声明不在正确的位置。OP在引导程序中使用了这一行。php

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

尝试更改使用的数据库。该行用于缓存文件,因此它无法控制数据库设置。要告诉模型使用另一个数据库(而不是default),您需要更改模型属性并进行

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

这只适用于一个模型,但如果你想为整个应用程序做这件事,你可以将这一行添加到AppModel 中

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

(当然,不要在其他型号中覆盖它)。