Welcome Guest, Not a member yet? Register   Sign In
[sqlite] How can I use it?
#1

[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.
#2

[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
#3

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

[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
#5

[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.
#6

[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
#7

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

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




Theme © iAndrew 2016 - Forum software by © MyBB