Welcome Guest, Not a member yet? Register   Sign In
SQLite and Codeigniter 2.0.2
#1

[eluser]Unknown[/eluser]
Hey all.

I've spent the morning trying to get SQLite and Codeigniter playing ball without much luck. I've had a look at the wiki and went through the core files and as far as I can work out CI 2.0.2 supports sqlite out of the box (like it says it does in the server reqs), which leads me to think I'm either doing something silly with my config or with Active Record.

Said config:

Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

As I understand it I shouldn't need to fill out the username and password as SQLite doesn't need any of that stuff. Perhaps I'm not specifying the dbdriver or database right, but I haven't been able to find any examples demonstrating the right way to go about it for 2.0.2.

If the above is correct then I must be going wrong with the Active Record. I couldn't find any examples of SQLite and Active Record working together each other so I assumed it'd be working the same way.

Here's the piece of code I'm using to test this (located in a model):

Code:
function write()
  {

    $test_data = array(
      'test_name' => 'Borange',
      'workplace' => 'Foo',
      'Hometown'  => 'Bar'
    );

    $insert = $this->db->insert( 'mytable', $test_data );
    
    if( $insert )
    {
      return true;
    }
    else
    {
      return false;
    }
  }

I had expected this to throw a 'table doesn't exist' error or something like that, because I hadn't used the forge yet. Instead I get:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Site::$db

Filename: core/Model.php

Line Number: 50


Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\delegate-this\application\models\database_testing_model.php on line 21

Not good.

If anyone could shed light on where I've gone wrong I'd be very grateful.

Cheers,
Ralph
#2

[eluser]NoticeableDesigns[/eluser]
Looks like you may not be loading the db library prior to your functions

Code:
$this->load->library('database');

If your application relies on the db for most of its operations you can load it in the autoload config as well.
#3

[eluser]Unknown[/eluser]
Вау хороший сайт, а Русских принимаете? Блог
#4

[eluser]Unknown[/eluser]
Плохо, что английского не знаю, нужно заняться саморазвитием




Theme © iAndrew 2016 - Forum software by © MyBB