「Php/codeigniter/db」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==DB自動接続== <pre> - $autoload['libraries'] = array(); + $autoload['libraries'] = array('database'); </pre>」) |
(→DB自動接続) |
||
行1: | 行1: | ||
− | == | + | ==db自動接続== |
+ | application/config/autoload.php | ||
<pre> | <pre> | ||
- $autoload['libraries'] = array(); | - $autoload['libraries'] = array(); | ||
+ $autoload['libraries'] = array('database'); | + $autoload['libraries'] = array('database'); | ||
+ | </pre> | ||
+ | |||
+ | ==手動接続== | ||
+ | 以下でデフォルトのdbに接続 | ||
+ | $this->load->database(); | ||
+ | |||
+ | ==db設定== | ||
+ | application/config/database.php | ||
+ | <pre> | ||
+ | $db['default'] = array( | ||
+ | 'dsn' => '', | ||
+ | 'hostname' => 'localhost', | ||
+ | 'username' => '', | ||
+ | 'password' => '', | ||
+ | 'database' => '', | ||
+ | 'dbdriver' => 'mysqli', | ||
+ | 'dbprefix' => '', | ||
+ | 'pconnect' => FALSE, | ||
+ | 'db_debug' => (ENVIRONMENT !== 'production'), | ||
+ | 'cache_on' => FALSE, | ||
+ | 'cachedir' => '', | ||
+ | 'char_set' => 'utf8', | ||
+ | 'dbcollat' => 'utf8_general_ci', | ||
+ | 'swap_pre' => '', | ||
+ | 'encrypt' => FALSE, | ||
+ | 'compress' => FALSE, | ||
+ | 'stricton' => FALSE, | ||
+ | 'failover' => array(), | ||
+ | 'save_queries' => TRUE | ||
+ | ); | ||
</pre> | </pre> |
2024年11月10日 (日) 02:44時点における版
db自動接続
application/config/autoload.php
- $autoload['libraries'] = array(); + $autoload['libraries'] = array('database');
手動接続
以下でデフォルトのdbに接続
$this->load->database();
db設定
application/config/database.php
$db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );