The _php example of the modification and checking operation in CI (CodeIgniter) frame

Source: Internet
Author: User

CodeIgniter data function classes in \system\database\db_active_rec.php

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" >class ModelName extends Ci_model
{
function __construct ()
{
Parent::__construct ();
}
}</span>

Connection database: $this->load->database ();

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" >classmodel_name extends Ci_model
{
function __construct ()
{
Parent::__construct ();
$this->load->database ();
}
}</span>

Written in the constructor of the model, it is convenient to load the model and connect the database at the same time.


Inserting data

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" > $this->db->insert ($tableName, $data);</span>
$tableName = is the name of the table you want to manipulate.
$data = The data you want to insert, inserted as an array (Key name = Field name, key value = field value, self-added primary key does not need to be written).

Update data

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" > $this->db->where (' field name ', ' field value ');
$this->db->update (' table name ', modified array of values);</span>

Querying data

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" > $this->db->where (' field name ', ' field value ');
$this->db->select (' field ');
$query = $this->db->get (' table name ');
Return$query->result ();</span>

Delete data

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" > $this->db->where (' field name ', ' field value ');
$this->db->delete (' table name ');</span>

Next we're going to call our model in the controller.

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" > $this->load->model (' model name ')//model name refers to you in <span style= "Color:rgb (255, 0, 0); "> project directory/models/</span> built under the model (same as the filename)
$this-> Model Name-> method name </span>

In order not to be called once in each controller's method. That's what I did.

Copy Code code as follows:

<span style= "FONT-SIZE:16PX;" >
Class Controllername extends Ci_controller
{
function __construct ()
{
Parent::__construct ();
$this->load->model (' model name ');
}
}</span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.