CodeIgniter Forums
[updated!] I just took over this project..."Fatal error: Call to a member function result_array() on a non-object in..." - 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: [updated!] I just took over this project..."Fatal error: Call to a member function result_array() on a non-object in..." (/thread-12156.html)



[updated!] I just took over this project..."Fatal error: Call to a member function result_array() on a non-object in..." - El Forum - 10-08-2008

[eluser]rbxbx[/eluser]
edit:

But now it’s a brand new error fest…

Screencap of errors

Hello All,

I've just taken over a project from another programmer, who left the migration of the application/site up to the client. It looks as though all has been transferred well (as CI seems easy to migrate).

I'm pretty familiar with php, however have never used CI before.

After changing .htaccess due to a 500 error, php is now throwing this error...

Quote:Fatal error: Call to a member function result_array() on a non-object in /data/18/1/11/157/1663320/user/1793798/htdocs/public_html/system/application/models/cms_data.php on line 133

here is the code that caused the error... (according to the error report)
Code:
function Datatype_Exists($typename)
    {
        $res = $this->db->query("SHOW TABLES");
        foreach($res->result_array() as $row)
        {
            foreach($row as $tmp) if($tmp == "type_".$typename) return true;
        }
        return false;
    }

searching google and the forums has been of little help so far, although I did find one similar thread...

Any help would be greatly appreciated!

ps: I'm glad this project is forcing me to finally look into CI, seems a good deal better than your other PHP frameworks!


[updated!] I just took over this project..."Fatal error: Call to a member function result_array() on a non-object in..." - El Forum - 10-08-2008

[eluser]Randy Casburn[/eluser]
@rbxbx,

Hi and welcome to CI. The db object discussed here http://ellislab.com/codeigniter/user-guide/database/queries.html in the docs returns a standard DB object that you can run through your foreach loop construct.

Looks to be a simple scope problem: $this references what exactly? You've not exposed us to the object that the Datatype_Exists method is a member of.

$this->db->query() assumes access to the CI super object. If we don't have direct access in our methods, we usually use the get_instance() method to create a reference to the CI super object thus:

Code:
$this->CI = & get_instance();
$this->CI->db->query('SHOW TABLES');

Hope this is helpful.

Randy


[updated!] I just took over this project..."Fatal error: Call to a member function result_array() on a non-object in..." - El Forum - 10-08-2008

[eluser]rbxbx[/eluser]
Code:
class Cms_data extends Model {

    var $field_types = array();


this is the class that the function belongs to, sorry for not clarifying that.

It calls query method several times before this instance, so I'm not sure if that's necessarily our solution, but I will certainly look into it.

I've not solved my problem quite yet, but you've definitely offered some valuable insight into the issue.

Thank you for your help sir (and prompt reply!)

-Robert

edit: Actually, I believe you've solved that problem. Now onto
Quote:Fatal error: Call to a member function num_rows() on a non-object in /data/18/1/11/157/1663320/user/1793798/htdocs/public_html/system/application/libraries/Db_session.php on line 193
C'est le vie!
(Although I think this could be handled in a similar fashion, I wish I was learning CI from the bottom up, instead of by debugging! Tongue )


[updated!] I just took over this project..."Fatal error: Call to a member function result_array() on a non-object in..." - El Forum - 10-10-2008

[eluser]rbxbx[/eluser]
I decided to download the site to a local XAMPP dev server, to see if maybe the issues were server/deployment side... and this does appear to have resolved that error...

But now it's a brand new error fest...

Screencap of errors

Am I "just not getting it" or is this project SNAFU from the git-go...

It was supposedly running live when I agreed to the project, mostly maintenance and mods...

here's the live version live server
and phpinfo() if it helps....


I'd hate to turn away this client... but if I can't get things working at all, it's not worth my time, or his money.