CodeIgniter Forums
[sqlite] How can I use it? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [sqlite] How can I use it? (/thread-19007.html)



[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]Sanity11[/eluser]
Hi everybody.

I am new to using sqlite and CI. What I have made with CI is done with a MySql database. But now we are going to create a website for a server that only supports SqlLite. Right now I am testing how to set this up, but I am missing some realy trivial information and knowledge on how to do this.

I have the following database settings (the test is locally so there is no password or username).

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
$db['default']['dbdriver'] = "sqlite";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";

I have this controller:

Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->helper('form');
        $this->load->helper('html');
        
        $this->load->view('welcome_message');    
    }
    
    function insertdata()
    {
        $this->load->model('sqlitetestmodel');
        $this->load->helper('html');
        
        //$insert_info['vnaam'] = $this->input->post('vnaam');
        //$insert_info['anaam'] = $this->input->post('anaam');
        
        $this->sqlitetestmodel->insertdata();
        
        $this->load->view('welcome_message');
    }
}

This is the model:

Code:
<?php
class Sqlitetestmodel extends Model
{
    function Sqlitetestmodel()
    {
        parent::Model();
    }
    
    function insertdata()
    {
        $this->load->database();
        
        $data = array(
                'voornaam' => $this->input->post('vnaam'),
                'achternaam' => $this->input->post('anaam')
                );
        
        $this->db->insert('testing', $data);
    }
}
?>

And of coures a view page:

Code:
<html>
<head>
<title>Welcome to CodeIgniter</title>


</head>
<body>

<h1>SQLite testing</h1>

&lt;?php echo form_open('welcome/insertdata'); ?&gt;
<table>
    <tr>
        <td>
            Voornaam:
        </td>
        <td>
            &lt;input type="text" name="vnaam" /&gt;
        </td>
    </tr>
    <tr>
        <td>
            Achternaam:
        </td>
        <td>
            &lt;input type="text" name="anaam" /&gt;
        </td>
    </tr>
</table>

&lt;input type="submit" value="insert"&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

This test is only meant to see how I can add data to the database.
Can someone help me set this up correctly?

Thanks in advance Smile.


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]René Tuin[/eluser]
I have the same problem, i also get the following error 'a database error has occur'
Has someone a solution for this problem.

Greetz


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
I think that $db['default']['database'] needs to be set to the path and file name of the database file.


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]Sanity11[/eluser]
Thanks, I was allready trying that.

Now I am having this error:

-----
A Database Error Occurred

Error Number: 14

unable to open database file

INSERT INTO testing (voornaam, achternaam) VALUES ('Piet', 'Puk')
-----

The database is set to Read/Write


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
That most likely indicates the the directory is not writeable, as the file should be created automatically if it doesn't exist.


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]Sanity11[/eluser]
That seems te be working! Only the entry's aren't shown in the database manager... But that may be a manager problem. I am going to see if I can get this info out of the db again! Smile


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]Sanity11[/eluser]
Thank you TheFuzzyOne. That's it!


[sqlite] How can I use it? - El Forum - 05-25-2009

[eluser]TheFuzzy0ne[/eluser]
The Fuzz prevails once again!