Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
3
Help us understand the problem. What is going on with this article?

More than 3 years have passed since last update.

@oshinco_

【FuelPHP】mysql接続でこけた話

- 開発環境

OS: X EI Capitan 10.11.6
PHP: 5.5.36
FuelPHP: 1.7.3
MySQL: 5.7.16

結論としてはFuelPHPでMySQLを使うための設定に抜けがあったことが原因.
今回は、拡張モジュール mysqli を使用した.

- 作業内容

localhostで開発をしていてDB接続するために,
fuel/app/config/development/db.php を下記でセット.

return array(
   'default' => array(
      'connection'  => array(
         'hostname' => 'localhost',
         'port'     => '3306',
         'database' => 'test_db',
         'username' => user',
         'password' => ‘xxxx',
      ),
        'profiling' => true,
   ),
);

次にfuel/app/config/db.php を下記でセット.

return array(
    'default' => array(
        'type'        => 'mysqli',
        'connection'  => array(
            'persistent' => false,
        ),
        'identifier'   => '`',
        'table_prefix' => '',
        'charset'      => 'utf8',
        'collation'    => false,
        'enable_cache' => true,
        'profiling'    => false,
        'readonly'     => false,
    ),

);

DB設定はこれだけであとは DB保存するための Model を作って、
Controller でデータを save( ) してあげればイケると思ったけどエラーでた.

Fuel\Core\PhpErrorException: mysqli::mysqli(): (HY000/2002): No such file or directory

この設定が必要だった.
fuel/core/classes/database/mysqli/connection.php

// Extract the connection parameters, adding required variables
extract($this->_config['connection'] + array(
   'database'   => 'test_db',
   'hostname'   => 'localhost',
   'port'       => '3306',
   'socket'     => '/tmp/mysql.sock',
   'username'   => user',
   'password'   => ‘xxxx',
   'persistent' => false,
   'compress'  => true,
));

これで無事解決!

3
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
3
Help us understand the problem. What is going on with this article?