I’m using the following instructions for using a CI model outside of CI:
http://codeigniter.com/wiki/Calling_CI_models_from_outside_script/
I have the three include files set up as described, as well as my main php file with the proper includes and such. Here’s what my main php file contains (concerning the CI model):
32 // These file allows us to access CI models without having to go through CI
33 require_once($CONFIG['CIMODEL_PATH'].'ci_model_remote_open.php');
34
35
36 // Loading a DbOps model which will allow us to carry on all of our DB Operations from outside of CI.
37 // This is part of the ci model interface.
38 require_once(APPPATH."/models/DbOps.php");
39
40
41 $DB = new DbOps;
42 $DB->_assign_libraries();
43 // The query() function will transform the CI response into a standard array of results for us
44 $arrResults = $DB->query('SELECT * FROM APPS');
( The closing file include is elsewhere )
My $DbOps->query() method naturally has a line saying $this->db->query(); which sends the SQL query off to the DB. When it gets to that line, I get this error:
Fatal error: Call to a member function on a non-object in /var/www/vhosts/launchcms.com/httpdocs/dev/launchcms/system/ci/system/application/models/DbOps.php on line 35
Line 35 in DbOps.php is the previously mentioned: $sqlResults = $this->db->query($strQuery);
Here’s the whole function for anyone who wants to see it:
29 // This will handle general queries to the DB.
30 function query($strQuery) {
31
32 $this->load->database();
33
34 // asking the DB for the information we need
35 $sqlResults = $this->db->query($strQuery);
36
37 // initializing the array of results we will be returning
38 $arrResults = array();
39
40 // Adding elements to the array of results from the sql response.
41 if ( $sqlResult->num_rows() > 0 ) {
42 for ( $i = 0; $i < $sqlResult->num_rows(); $i ++ ) {
43 // Adding every row as an array element in our resuls array
44 $arrResults[$i] = $sqlResults->row_array($i + 1);
45 }
46 }
47 else {
48 $arrResults[0] = "No Results Returned";
49 }
50
51
52 return $arrResults;
53
54
55 }
Does anyone have any idea why this might be giving me this error? Obviously the writer of the original wiki article wasn’t getting it so I’m thinking that it’s just something that I’m doing wrong. Thanks for any help you can give!
