首页 > 解决方案 > Prestashop: 'Link to database cannot be established'

问题描述

This is our first time moving a Prestashop Installation from one Domain to another and it has been one hell of a learning curve.

Steps we have taken so far:

Copied the database: 0) New database name: gamingco_ps, user gamingco_ps1

  1. Changed ps_configuration
  2. Changed the ps_shop_url (Domain/Domain SSL)
  3. Amended htcacess to stop any redirects
  4. CPANEL removed all temporary redirects
  5. Changed the /home/gamingco/public_html/app/config/parameters.php :
<?php return array (
  'parameters' => 
  array (
    'database_host' => 'localhost',
    'database_port' => '',
    'database_name' => 'gamingco_ps',
    'database_user' => 'gamingco_ps1',
    'database_password' => '{Password}',
    'database_prefix' => 'pswy_',
    'database_engine' => 'InnoDB',
    'mailer_transport' => 'smtp',
    'mailer_host' => '127.0.0.1',
    'mailer_user' => NULL,
    'mailer_password' => NULL,
    'secret' => 'dva3atuoqjpqhb8xmjtfwjszkpbwaifombdlbg46qwygbi7e4mpyfgui',
    'ps_caching' => 'CacheMemcache',
    'ps_cache_enable' => false,
    'ps_creation_date' => '2021-01-27',
    'locale' => 'en-US',
    'use_debug_toolbar' => true,
    'cookie_key' => 'zml9yqgynwgixtb1e4c0xh8q8gjeynsp7arnovqw5dhpcthcyfpu89bx',
    'cookie_iv' => 'qsembkbmpfbnk5bf3hhxjg3sw1laaa06',
    'new_cookie_key' => 'def00000acce4699cd116debb37dc5533dfd6ff201153a61ac3446801d772207548a0f44596a7a01939e9f753e4290f3735373a25516e62b2118322ec7f7cd64e3b347ee',
  ),
);

We are now receiving error 500 without debug mode and with debugmode we are met with:

Link to database cannot be established: SQLSTATE[28000] [1045] Access denied for user 'gamingco_ps1'@'localhost' (using password: YES)
at line 136 in file classes/db/DbPDO.php
131.     public function connect()
132.     {
133.         try {
134.             $this->link = $this->getPDO($this->server, $this->user, $this->password, $this->database, 5);
135.         } catch (PDOException $e) {
136.             throw new PrestaShopException('Link to database cannot be established: ' . $e->getMessage());
137.         }
138. 
139.         $this->link->exec('SET SESSION sql_mode = \'\'');
140. 
141.         return $this->link;```
DbPDOCore->connect - [line 330 - classes/db/Db.php]
DbCore->__construct - [line 241 - classes/db/Db.php] - [4 Arguments]
DbCore::getInstance - [line 47 - config/alias.php]
pSQL - [line 1336 - classes/shop/Shop.php] - [1 Arguments]
ShopCore::findShopByHost - [line 337 - classes/shop/Shop.php] - [1 Arguments]
ShopCore::initialize - [line 118 - config/config.inc.php]
require - [line 27 - index.php] - [1 Arguments]

I gone through all the steps again and I cannot seem to identify where the error maybe.

标签: mysqldatabase-migrationprestashop-1.7

解决方案


Error is pretty straighforward here, Prestashop cannot connect to database.

Things to check:

  • Make sure your var/cache/prod directory does not contain any cache file from previous installation as it can lead to old DB connection with old credentials.

  • Double check DB data in parameters.php, carefully look for data correctness (case sensitive, correct DB host / port etc.)

If none of above helps, try connecting your box from ssh and check direct db connection from there with :

mysql -u{username} -p{password} {database name}

and post the result.


推荐阅读