4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC-CUBE3 consoleでデーターベース接続エラー

Last updated at Posted at 2017-01-13

環境

  • EC-CUBE3
  • MAMP
  • mac

EC-CUBEではコンソール上で
$php app/console router:debug
と打つとフック一覧が見れるらしい。

ということで実行してみたところ

<!doctype html>
<html lang="ja">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>データーベース接続エラー</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="/html/template/default/img/common/favicon.ico">
    <link rel="stylesheet" href="/html/template/default/css/style.css?v=3.0.13">
    <link rel="stylesheet" href="/html/template/default/css/default.css?v=3.0.13"><!-- for original theme CSS -->
・・・・以下省略
</html>

こんなエラーが出てしまったのでDB接続周りを調べてて、ハッと思い出しました。
MAMP環境ではDB接続にsocketの設定がいる。

それを踏まえつつソースを辿っていくと、ありました!

Driver.php
protected function constructPdoDsn(array $params)
{
    $dsn = 'mysql:';
    if (isset($params['host']) && $params['host'] != '') {
        $dsn .= 'host=' . $params['host'] . ';';
    }
    if (isset($params['port'])) {
        $dsn .= 'port=' . $params['port'] . ';';
    }
    if (isset($params['dbname'])) {
        $dsn .= 'dbname=' . $params['dbname'] . ';';
    }
    // unix_socket!こいつを使えばいいはず!
    if (isset($params['unix_socket'])) {
        $dsn .= 'unix_socket=' . $params['unix_socket'] . ';';
    }
    if (isset($params['charset'])) {
        $dsn .= 'charset=' . $params['charset'] . ';';
    }
    return $dsn;
}

上の関数を見つけたので、以下のようにdatabase.ymlに追記

database.yml
database:
    driver: pdo_mysql
    host: localhost
    dbname: hogehoge
    port: 
    user: hogehoge
    password : hogehoge
    charset: utf8
    defaultTableOptions: { collate: utf8_general_ci }
    // これを追記
    unix_socket: /Applications/MAMP/tmp/mysql/mysql.sock

そのあとに
$php app/console router:debug
を試したら見事フック一覧が出力されました!

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?