Skip to content

Instantly share code, notes, and snippets.

@yuigoto
Last active February 14, 2023 06:25
Show Gist options
  • Save yuigoto/35aa2d0a7c3988a54c791fc4e4b6327c to your computer and use it in GitHub Desktop.
Save yuigoto/35aa2d0a7c3988a54c791fc4e4b6327c to your computer and use it in GitHub Desktop.
[PHP : CodeIgniter Config] How to setup PDO and SQLite for CodeIgniter (for SQLite and MySQL). This is the `database.php` file in `the application/config` folder #codeigniter
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'default';
$query_builder = TRUE;
// FOR SQLITE
$db['default'] = array(
'dsn' => 'sqlite:[path-to-database-file]',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => TRUE,
'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
);
// FOR MYSQL
$db['default'] = array(
'dsn' => 'mysql:host=[host-address];dbname=[db-name]',
'hostname' => '[host-address]',
'username' => '[db-username]',
'password' => '[db-password]',
'database' => '[db-name]',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => TRUE,
'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
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment