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)