Welcome Guest, Not a member yet? Register   Sign In
CI4 and sqlite
#1

Hello I would like to create a simple application using sqlite. I am starting from scratch and I hope that it is stable enough for soon production.

I am in my first day and I used to code with CI3 but I wanted to learn CI4.

I install CI4 and see the defaut welcome page

Then I create a Test.php controler to test the database. My goal is to read, update and delete row of a table.

First test with mysql is ok I can read my data

I add this

       $db = db_connect();
       $strsql = "select * from aaa";
       $query = $db->query($strsql);

       $results = $query->getResult();

        foreach ($results as $row)
        {
               echo '<br/>'.$row->uscode;
        }
       


Now with sqlite I have this
1. Database.php
    public $default = [
        'DSN'      => '',
        'hostname' => '',
        'username' => '',
        'password' => '',
        'database' => APPPATH . 'Database/db1.db',
//      'DBDriver' => 'MySQLi',
        'DBDriver' => 'sqlite3',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => (ENVIRONMENT !== 'production'),
        'cacheOn'  => false,
        'cacheDir' => '',
        'charset'  => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'     => 3306,
    ];


I have db1.db that I put in  app/Database directory
 I have an error.  I notice that the linethat gave me the error is

       $db = db_connect();

What is wrong what did I miss?
In the documentation I didn't see anything with sqlite configuration.
Reply
#2

I hope my question is clear because this forum put color in my text. I hope you understand. How to configure slqite after 3 days I didn't find
Reply
#3

Your capitalization is off with driver name, try SQLite3 (capitalization counts).

And ensure your file actually exists at APPPATH . 'Database/db1.db'. Otherwise it should work, though most of the time I use with an in-memory database for testing purposes, so I'm not 100% up on SQLite usage, but that should be good.
Reply
#4

Thank you very much. It works. "SQLite3"
Reply
#5

I have an other question. Where do you suggest to place the database. I put it in App/Database

But maybe it is not a good decision. I have to consider the maintenance, saving the database, installation etc..? Database is data and App/Database is not a directory to store data. What is your idea ?
Reply
#6

The writable folder could be a good place ... writable/database
Reply
#7

I'm using also SQLite for some projects, and the "writable" folder is for sure the obvious spot for the database.
Reply
#8

(10-09-2019, 04:32 AM)ciadmin Wrote: The writable folder could be a good place ... writable/database

 i'm tightening up security  even on localhost in anticipation of hardening live. Mine was in public ; i also moved it to writeable .

so line i am using for Database.php in Config that works is :



'database' => ROOTPATH.'writable/Art',

where Art is a Sqlite database
Reply
#9

(10-12-2019, 05:55 PM)AndreiCurelaru Wrote: I'm using also SQLite for some projects, and the "writable" folder is for sure the obvious spot for the database.

Hi Bro 
i'm tring to connect SQLite3 with CI4 but i cant , it works fine with CI3
PLZ could you give the right configuration ...thanks very much
Reply
#10

How to connect CodeIgniter to sqlite3 database like a PRO
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB