Welcome Guest, Not a member yet? Register   Sign In
troubles conecting to a sqlite database
#1

[eluser]plainas[/eluser]
Hey all, i am using CI for the first time now.

Ok, i am trying to use a sqlite database but i am not being able to connect.

What's the path i have to define? Like... in which follder does the path starts?


Also, is there anyway to enable database errors and connection failure warnings? I'm getting a blank page because the connections is failing, but it would be cool to have some error messages instead.
#2

[eluser]gtech[/eluser]
silly answer this probably, have you checked you system\application\config\database.php file?

which OS are you running?
which webserver are you running codeigniter on?
is codeigniter up and running (can you write a simple controller to display a test page)?

I am not sure exactly how much help you need but I will give you the steps I used to get everything running.

I used xampp (search google) for my installation on windows, it installs mysql for you and configures it to run with apache. Then all I needed to do was download the code igniter framework and place it in C:\xampp\htdocs\codeigniter\ and then change:

application/config/config.php to configure the baseurl
e.g.
Code:
if ($_SERVER['HTTP_HOST'] == 'localhost')
{
    $config['base_url'] = 'http://localhost/codeigniter/';
}
application/config/database.php to configure the database (the variables should be self explanitry).

If you look at the routes.php file you can set your default controller .. mine is 'start' and it looks for a file start.php in the controllers directory (you can write your first controller here and try a db call).

Code:
<?php
class Start extends Controller {

  function Start()
  {
    parent::Controller();
  }
  function index()
  {
    echo "HELLO WORLD:<BR>";
    $res = $this->db->get('mydbtable');
    print_r($res->result_array());
  }

?&gt;

the index.php in the root of your codeigniter installation can be called from your web browser (see base_url above) and your controller should pop up, as the index.php reads in all the config files automatically for you!

if db_debug is TRUE in the database.php any error should pop up! connection errors should be displayed in your webserver log.
#3

[eluser]plainas[/eluser]
I appreciate your help but i'm afraind you didn't understand my problem.

See, sqlite does not have a network connection layer like mysql, all it takes it's a file and the library is the database engine itself.

Everything works, perfectly i red the documentation through and played around with codeignitor.

There's no problem with mysql, i can connect mysql without any problem,the problem is sqlite. I need Like, i need to define the path to the db file but the documentation is not clear about that.

like... if i just place the filename as the database name, where is it suposed to go?

aparently the document root is not the database include root.
#4

[eluser]gtech[/eluser]
Ok sorry, I wasn't quite sure what you were asking.. I'll have I hunt around the forums but I do have no idea :-( anyone else?
#5

[eluser]gtech[/eluser]
reading the docs I guess the following:-

config/database.php
Code:
$db['default']['database'] = "<your sqlite path goes here>";

if you scroll down to the bottom of the documentation
I guess you have tried that already?
#6

[eluser]plainas[/eluser]
[quote author="gtech" date="1194161028"]reading the docs I guess the following:-

config/database.php
Code:
$db['default']['database'] = "<your sqlite path goes here>";

if you scroll down to the bottom of the documentation
I guess you have tried that already?[/quote]

yes, i've tried that. But it's not clear where that path starts.

Like, if i enter 'sqlite.db' there where is the file suposed to go?
In the root of the server?
In the project main directory?
in the application directory?
in the config directory?
in the controller directory?
#7

[eluser]gtech[/eluser]
I have tried hunting the web everywhere for you.. but cannot find any resource to tell you where the sqlite path should be set.

Best bet try relative to root of your codeigniter install (that seems to be the case for most things)

<codeigniter_install>\sqlitedb\file.db

Code:
$db['default']['database'] = "./sqlitedb/file.db";

then try full system path (eg. c:\sqllite\file.db) and then if no joy, rename this post with the title 'sqlite configuration problems' and see if you get more responses :-). I will be interested to know how you get on.
#8

[eluser]plainas[/eluser]
I've done that actually.
The problem is that there is no error message. That sucs as i can't be sure if the file is in the right place or if there's something with it, etc.
#9

[eluser]gtech[/eluser]
While you wait for sombody who knows what they are doing with sqlite to respond..... another thing you can do is to put some echo's in the <install_dir>\system\database\drivers\sqlite\sqlite_driver.php as that file seems to deal with the connections (how ever it does seem to display connection errors if db_debug is TRUE). at least with putting some echo's in you can see if its getting that far.
#10

[eluser]gtech[/eluser]
Ahhh! another brainwave after reading the code.. if you want some logging try setting your config.php log_threshold to 1 (error) or 2 (debug)... then codeingiter will log any database load errors.

config.php
Code:
$config['log_threshold'] = 1;

as log_message('error','<message>')

is used throughout the system\database\DB_driver.php file (which appears to load the configuration) at least then you can find out where it keels over. the log should appear in the /log directory of you install dir




Theme © iAndrew 2016 - Forum software by © MyBB