CI Framework-database (add and revise)

Source: Internet
Author: User

1: Configuration database (application/config/database.php) modification

$db [' default '] = Array (
' DSN ' = ',
' hostname ' = ' localhost ',
' username ' + ' database username ',

' Password ' = ' database password ',
' Database ' = ' data table name ',
' Dbdriver ' = ' mysqli ',
' Dbprefix ' = ',
' Pconnect ' = TRUE,
' Db_debug ' = TRUE,
' cache_on ' = FALSE,
' Cachedir ' = ',
' Char_set ' = ' UTF8 ',
' Dbcollat ' = ' utf8_general_ci ',
' Swap_pre ' = ',
' Encrypt ' = FALSE,
' Compress ' = FALSE,
' Stricton ' = FALSE,
' Failover ' = = Array (),
' Save_queries ' = TRUE
);

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

3: Increase:

Insert
Syntax: $bool = $this->db->insert (' table name ', associative array);
$data =array ( ' username ' = ' mary ', ' password ' and ' Mary ',//create an array of user name Mary, the password is Mary, and pass it to the variable $data); $bool = $this->db->insert (' user ', $data);//insert $data into the user table of the database Var_dump ($bool);//Success Returns ture

4: Delete:
Delete
Syntax: $bool = $this->db->delete (' table name ', where condition); $bool = $this->db->delete (' user ', array (' ID ' =>3));// Delete the database. User table id=3 All information var_dump ($bool);//Success Returns ture
5: Change:
Update$data=array (    ' password ' =>12345,); $bool = $this->db->update (' user ', $data, array (' ID ' =>3) ;//The user password for the database. Id=3 to 12345
Var_dump ($bool);//Success Returns ture

6: Check:
get$res= $list = $this->db->get (' user ');//var_dump ($list); foreach ($res->result () as $item) {// Use foreach to list all user names    echo $item->username;echo ' <br/> ';}

Federated query:

$this->db->join (' ci_role ', ' ci_role.role_id = ci_admin.role_id ', ' left ');
$query = $this->db->get_where (' ci_admin ', Array (' username ' = $arr [' username '], ' pwd ' = $pwd));
$res = $query->result ();

CI Framework-database (add and revise)

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.