how executed within a helper to $ this-> db-> query (); - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: how executed within a helper to $ this-> db-> query (); (/showthread.php?tid=25596) |
how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]Lic. Roberto Estupiñán Pérez[/eluser] hi: I'm trying to make a helper to restore a database, but I can not run $ this-> db-> query (); thks. restore_helper.php Code: <?php how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]intractve[/eluser] You will need to access the current instance first by using Code: $CI &= get_instance(); Then from that point forward you use $CI instead of $this you will have to do this for every function or call -- or -- do this from your constructor function. Code: $this->ci &= get_instance(); then use $this->ci->db->get(); to access the database library from your class functions. how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]Lic. Roberto Estupiñán Pérez[/eluser] i'm do this: function _Query($sql){ $CI &= get_instance(); $this->ci &= get_instance(); $result = $this->ci->db->query($sql); return $result; } but show this error: Undefined variable: CI Filename: helpers/restore_helper.php Line Number: 35 Message: Object of class Admin could not be converted to int Filename: helpers/restore_helper.php Line Number: 35 Message: Trying to get property of non-object Filename: helpers/restore_helper.php Line Number: 37 Fatal error: Call to a member function query() on a non-object in /var/www/pt/application/helpers/restore_helper.php on line 37 how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]intractve[/eluser] Im sorry if I had not been clear, Do only this: $CI &= get_instance(); inside a function, and then use it like this Code: function _Query($sql){ how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]Lic. Roberto Estupiñán Pérez[/eluser] thk!!! Work!!!! but i need change $CI &= get_instance(); by $CI = get_instance(); because what??? how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]intractve[/eluser] What version of PHP are u using? how executed within a helper to $ this-> db-> query (); - El Forum - 12-17-2009 [eluser]intractve[/eluser] I have made a typo, it is supposed to be $CI =& get_instance(); if you use just =, you are copying the original object rather than working with the existing one. |