코드이그나이터의 DB 클래스 사용법 모음
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-07-25 09:05:36
-
-
链接数据库
- -------
- $this->load->database();//手动连接数据库
- //连接多数据库
- $DB1 = $this->load->database('group_one', TRUE);
- $DB2 = $this->load->database('group_two', TRUE);
查询
- -------
- //参数绑定形式
- $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
- $this->db->query($sql, array(3, 'live', 'Rick'));
- //多结果标准查询
- $query = $this->db->query($sql); //自定义
- $query = $this->db->get('tablename'); //便捷形式,相当于:SELECT * FROM tablename
- $query = $this->db->get('tablename', 10, 20); // 相当于: SELECT * FROM tablename LIMIT 20, 10
- $query->result() //对象形式
- $query->result_array() //数组形式
-
- $query->num_rows() //总条数
- $query->num_fields() //字段数
- //单结果标准查询
- $row = $query->row(); //对象形式
- $row = $query->row_array(); //数组形式
-
- 插入
- -------
- $data = array(
- 'title' => $title,
- 'name' => $name
- );
- $this->db->insert('tablename', $data); //便捷插入
- $this->db->insert_string('tablename', $data); //便捷插入
- $this->db->insert_id() //刚插入的id
- $this->db->affected_rows() //影响的行数(update,insert)
更新
- -------
- $data = array(
- 'name' => $name,
- 'email' => $email
- );
- $where = "id = 1";
- $this->db->update('tablename', $data);
- $this->db->update_string('tablename', $data, $where);
删除
- -------
- $array = array(
- 'name' => $name,
- 'title' => $title
- );
- $this->db->delete('tablename', $array);
- // Produces:
- // "DELETE FROM tablename WHERE name = '$name' AND title = '$title'"
- $this->db->truncate('tablename'); //清空表
- // Produce: TRUNCATE tablename
(where)
- -------
- $array = array(
- 'name' => $name,
- 'title' => $title
- );
- $this->db->where($array);
- // Produces: "WHERE name = '$name' AND title = '$title'"
- -----------------------------------------------------
- $this->db->count_all('tablename'); //表中记录总行数
- -----------------------------------------------------
- $query->free_result() //释放资源
-
复制代码
|
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
-
2025-02-25 19:29:11
-
2025-02-25 19:10:11
-
2025-02-25 18:38:08
-
2025-02-25 18:16:09
-
2025-02-25 17:59:10
-
2025-02-25 17:12:10
-
2025-02-25 17:10:11
-
2025-02-25 17:07:11
-
2025-02-25 16:38:09
-
2025-02-25 15:26:10