Welcome Guest, Not a member yet? Register   Sign In
Database access error
#1

[eluser]Perkin5[/eluser]
I've started following Jeffrey Way's Nettuts CodeIgniter video tutorials but although my code follows his exactly, I get an error at the line where the model function tries to 'get' a database table using active_record syntax.

The code is
Code:
$q = $this->db->get('test');
The error is Fatal error: Call to a member function get() on a non-object

I have the code on my website where you can see the problem:

www.mikeheath.co.uk

and I'm wondering if the codeigniter version I have (2.0.2) differs substantially from the one he was using (1.7.1). I've already noticed that the base classes are now called CI_model etc instead of just model and there may be other changes. Is the active_record syntax the same?

By the way, I have checked the database config settings using a non-codeigniter file. Check it yourself at www.mikeheath.co.uk/dbtest.php

Grateful for any suggestions as to what is wrong.
#2

[eluser]gigas10[/eluser]
Code:
Message: Undefined property: Site::$db

Doesn't look like you put $this-> infront of db.
#3

[eluser]Perkin5[/eluser]
I certainly did!

I've since downloaded Jeffrey's code from Nettuts, ran it and it worked - remember that's with Codeigniter 1.7.1

I then cut and pasted his code into Codeigniter 2.0.2 and lo and behold I get exactly the same error as I've been getting. I think there's been some update to Codeigniter that's changed the syntax but despite hours of work and research on the web I've got nowhere.

Arrgh!
#4

[eluser]Iván Argulo[/eluser]
I'm getting the same error with every library I load, but only in some controllers... I'm stuck at this. I've been developing with CI for 3 years, versions from 1.3 to 1.7. Now I decided to move on to CI 2.0, but I'm not able to make it work...
#5

[eluser]Perkin5[/eluser]
We must pray for a guru!
#6

[eluser]Iván Argulo[/eluser]
Are you using hooks?
#7

[eluser]danmontgomery[/eluser]
Hate to ask, but you are loading the database, yes?

You didn't happen to do something like this, did you?

What do you see when you print_r() on $this in the model?
#8

[eluser]Perkin5[/eluser]
for Ivan: no I'm not using hooks - whatever they are.

for Noctrum:

I entered the necessary items in the database config file and then did an active record statement to get the table. Is there anything else I should have done to call the database? I know the database details are correct because I placed a file in the root called dbtest.php and if you go to http://www.mikeheath.co.uk/dbtest.php you can see the database contents echoed out as King and Queen.

I haven't done anything like the autocomplete modification mentioned in your ref. In fact I haven't touched any file in the System folder.

print_r produced no result.

I don't know whether you are familiar with NettutsPlus and Jeffrey Way's video series "Codeigniter from Scratch" but I'm still on video 1 of 17! I merely copied his code, which works fine in 1.7.1 but doesn't in 2.0.2. I'm therefore assuming some change in syntax.
#9

[eluser]Perkin5[/eluser]
Hi Noctrum,

Whaddayaknow - you were right. I hadn't loaded the database. I failed to understand the autoload config file, which has changed since 1.7.1 - 'database' is now included counter-intuitively under 'libraries', unlike in the codeigniter video. Anyway I did that and now I get an output from the database.

Many many thanks for your help - I can't tell you how much it means for a newb to have his hand held!!!




Theme © iAndrew 2016 - Forum software by © MyBB