0
1

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 3 years have passed since last update.

【FuelPHP,エラー対処法】Uncaught Fuel\Core\PhpErrorException: mysqli::__construct(): (HY000/2002):

Last updated at Posted at 2020-06-27

#はじめに

MacOS
フレームワーク:FuelPHP
MAMP

#エラー内容

cronで実行しようとすると下記のエラー

 Uncaught Fuel\Core\PhpErrorException: mysqli::__construct(): (HY000/2002): 

#解決法

db.php 内の "localhost" を "127.0.0.1" に変更します。

fuel/app/config/db.php
//変更前
'default' => array(
        'type'   => 'mysqli',
        'connection' => array(
            'hostname'   => 'localhost',
            'port'       => '3306',
            'database'   => 'db_name',
            'username'   => 'root',
            'password'   => '',
            'persistent' => FALSE,
        ),
        'identifier' => '`',
        'table_prefix' => '',
        'charset'      => 'utf8mb4',
        'caching'      => false,
        'profiling'    => true,
),

//変更後
'default' => array(
        'type'   => 'mysqli',
        'connection' => array(
            'hostname'   => '127.0.0.1',
            'port'       => '3306',
            'database'   => 'db_name',
            'username'   => 'root',
            'password'   => '',
            'persistent' => FALSE,
        ),
        'identifier' => '`',
        'table_prefix' => '',
        'charset'      => 'utf8mb4',
        'caching'      => false,
        'profiling'    => true,
),

公式ドキュメントにも書いてありましたね。笑

スクリーンショット 2020-06-27 10.10.18.png

ちなみにMySQLのソケットファイル(mysql.sock)が見当たらない場合にこのエラーが発生することもあるようです。
https://k-holy.hatenablog.com/entry/2014/05/28/192707
実はずっとこっちが原因ではないかと試行錯誤していました。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?