![]() |
database access using code igniter - 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: database access using code igniter (/showthread.php?tid=22067) |
database access using code igniter - El Forum - 08-28-2009 [eluser]subhashramesh[/eluser] Hi all, I am new to codeigniter and i tried to access databse as follows. my databse name is 'efo' and and it has table 'sample' with 3 columns namely a,b,c respectively. CONFIG.PHP settings i changed as follows. $config['base_url'] = "https://127.0.0.1/CodeIgniter_1.7.1/"; $config['rewrite_short_tags'] = TRUE; DATABSE.PHP settings i changed as follows. $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = ""; $db['default']['database'] = "efo"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; AUTOLOAD.PHP i changed settings as follows. $autoload['libraries'] = array('database'); my model file as Helloworld_model.php as follows. <?php class Helloworld_model extends Model { function Helloworld_model() { // Call the Model constructor parent::Model(); } function getData() { //Query the data table for every record and row $query = $this->db->get('sample'); if ($query->num_rows() < 0) { //show_error('Database is empty!'); }else{ return $query->result(); } } } ?> my controlfile Helloworld.php as follows. <?php class Helloworld extends Controller{ function index() { $this->load->model('Helloworld_model'); $data['result'] = $this->Helloworld_model->getData(); $data['page_title'] = "CI Hello World App!"; $this->load->view('helloworld_view',$data); } } ?> my view file helloworld_view.php as follows. <html> <head> <title><?=$page_title?></title> </head> <body> <?php foreach($result as $row):?> <h3><?=$row->a?></h3> <p><?=$row->b?></p> <p><?=$row->c?></p> <br /> <?php endforeach;?> </body> </html> but i am getting error as follows. A PHP Error was encountered Severity: Notice Message: Undefined property: Helloworld::$Ok1 Filename: libraries/Loader.php Line Number: 1038 Fatal error: Call to a member function _assign_libraries() on a non-object in C:\xampp\htdocs\CodeIgniter_1.7.1\system\libraries\Loader.php on line 1038 could you please anyone solve this problem. database access using code igniter - El Forum - 08-28-2009 [eluser]MindFeed[/eluser] Hey, I don't see a constructor in your controller class "Helloworld.php", so if you write something like this, will work <?php class Helloworld extends Controller{ function Helloworld() { parent::Controller(); } function index() { $this->load->model(‘Helloworld_model’); $data[‘result’] = $this->Helloworld_model->getData(); $data[‘page_title’] = “CI Hello World App!”; $this->load->view(‘helloworld_view’,$data); } } ?> Thanks, Bhargav Khatana database access using code igniter - El Forum - 08-28-2009 [eluser]InsiteFX[/eluser] And next time you post please use tag blocks makes it a lot easier to read your code. Enjoy InsiteFX |