Welcome Guest, Not a member yet? Register   Sign In
database access by code igniter
#1

[eluser]subhashramesh[/eluser]
Hi all,could you please respond ............
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();
}
}

}
?&gt;

my controlfile Helloworld.php as follows.
&lt;?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);
}
}
?&gt;

my view file helloworld_view.php as follows.
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=$page_title?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php foreach($result as $row):?&gt;


&lt;?=$row->a?&gt;

&lt;?=$row->b?&gt;
&lt;?=$row->c?&gt;


&lt;?php endforeach;?&gt;
&lt;/body&gt;
&lt;/html&gt;
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.

Profile PM
Edit Quote


Messages In This Thread
database access by code igniter - by El Forum - 08-28-2009, 05:27 PM
database access by code igniter - by El Forum - 08-28-2009, 06:27 PM
database access by code igniter - by El Forum - 08-29-2009, 01:44 AM
database access by code igniter - by El Forum - 08-31-2009, 05:19 AM
database access by code igniter - by El Forum - 09-01-2009, 12:46 AM
database access by code igniter - by El Forum - 09-01-2009, 09:09 AM
database access by code igniter - by El Forum - 09-05-2009, 01:16 AM
database access by code igniter - by El Forum - 09-05-2009, 03:19 AM
database access by code igniter - by El Forum - 09-05-2009, 04:43 AM
database access by code igniter - by El Forum - 09-05-2009, 05:15 AM
database access by code igniter - by El Forum - 09-12-2009, 11:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB