aid

Monday, 13 April 2015

database class codeigniter


database class codeigniter
Initializing the Database Class
The following code loads and initializes the database class based on your configuration settings:
$this->load->database();
Once loaded the class is ready to be used as described below.

Note: If all your pages require database access you can connect automatically. See the connecting page for details.
Active Record Query

$query = $this->db->get('table_name');

foreach ($query->result() as $row)
{
    echo $row->title;
}
The above get() function retrieves all the results from the supplied table. The Active Record class contains a full compliment of functions for working with data.
Active Record Insert
$data = array(
               'title' => $title,
               'name' => $name,
               'date' => $date
            );

$this->db->insert('mytable', $data);

// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')

No comments:

Post a Comment