0
votes

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
Share your database.php file here. Omit the username and password information, I'm mostly interested in what you added in the port or socket key.José Lorenzo Rodríguez
I updated my post above.Geetix
the connection you mention for your main site, does it use cakephp too? or plain php or something else? how are you telling cakephp to use $ovh?Nunser
My main site use cakephp too with the same database as this app. In boostrap.php, in Cache::config, I write 'ovh' instead of 'default'.Geetix
do you mean this line Cache::config('default', array('engine' => 'File'));? That's for cache, not database settings.Nunser

2 Answers

1
votes

Did you update your database config after uploading to server? Based on the error message I think not.

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

I really doubt OVH servers would be using XAMPP.

0
votes

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