How to connect CodeIgniter to sqlite3 database like a PRO

Besarion Turmanauli
3 min readFeb 15, 2019

--

CodeIgniter comes with ready-to-use libraries for almost all standard databases, once you connect your database, you can use standard MySQL queries and query builders so you don’t need to modify your code at all.

Steps to connect CodeIgniter to sqlite3 database

  1. Go to your CodeIgniter directory / application and create a new folder named “db”.
  2. Copy your sqlite3 database file inside this newly created folder.
  3. Go to your CodeIgniter directory / application / config /database.php and modify $db[‘default’] so that it looks exactly like this (you can copy this code and replace there):
$db['default'] = array(
'dsn' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => './application/db/database.sqlite',
'dbdriver' => 'sqlite3',
'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
);

as you can see, your database location is indicated as

'database' => './application/db/database.sqlite'

If you need to modify database location or its name, make sure you set the correct location and name here as well.

Want free cloud hosting?

Go to this link and register to get $100 in cloud credits from DigitalOcean today and deploy your app in seconds. DigitalOcean is one of the best cloud services providers in the world today, check this medium article to know more.

There’s more:

$100 Free Money from FBS

$100 Free Money from FBS : regulated by IFSC, this broker is one of the oldest and most established out there, operating since 2009.

Requirements:

Available Markets: Cryptocurrencies, Stocks, CFDs, Metals, Commodities, Foreign Exchange

Claim your free $100 now and earn risk-free money!

$30 Free Money from Tickmill

$30 Free Money from Tickmill : regulated by FSA, this broker operates since 2015.

Requirements:

Available Markets: Stock Indices, Oil, Precious Metals, Bonds, Foreign Exchange.

Claim your free $30 now and earn risk-free money!

$30 Free Money from Roboforex

$30 Free Money from Roboforex : regulated by CySEC and IFSC, Roboforex is operating since 2009 and is one of the most popular brokers among traders today.

Requirements:

  • Open an account and deposit $10 in order to verify your payment method (can be withdrawn at any time) and get $30 as a gift
  • Profits are withdrawable without limitations
  • If you trade the necessary number of lots, you can withdraw the $30 too

Available Markets: Stocks (all NYSE, NASDAQ, and AMEX shares + German and Chinese listed companies), Stock CFDs (on all stocks, $1.5 per trade fee on US listed shares), Indices, ETFs, Commodities, Metals, Energy Commodities, Cryptocurrencies, Cryptoindices, Foreign Exchange.

Claim your free $30 now and earn risk-free money!

Thank you for reading. If you enjoyed this article, feel free to hit that clap button to help others find it.

--

--

No responses yet