ci手册:http://codeigniter.org.cn/user_guide/
CI操作数据库
$this->load->database();//必须先载入数据库
//$dsn = 'dbdriver://root:root@localhost/cnmobi';
//$this->load->database($dsn);
$query = $this->db->get('form_1_liuyan')->result();
查询指定字段数据
$member = $this->db->where('username', $data['username'])->get('member')->row_array();
$this->db->select('inputtime, xingming,youxiang,neirong');
$query = $this->db->get('form_1_liuyan')->result();
<?php
class Data_model extends Model {
function getAll() {
$q = $this->db->query("SELECT * FROM data");
if($q->num_rows() > 0) {
foreach($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function getAll() {
$q = $this->db->get('data');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function getAll() {
$this->db->select('title, contents');
$q = $this->db->get('data');
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function getAll() {
$sql = "SELECT title, author, contents FROM data WHERE id = ? AND author = ?";
$q = $this->db->query($sql, array(2, 'Jeffrey Way'));
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function getAll() {
$this->db->select('title, contents');
$this->db->from('data');
$this->db->where('id', 1);
$q = $this->db->get();
if($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
}
JSON
JSON_UNESCAPED_UNICODE json要编码Unicode
echo json_encode("中文"); //"\u4e2d\u6587"
echo json_encode("中文", JSON_UNESCAPED_UNICODE); //"中文"
转码问题,将html字符串转成html实体
$k['content'] = htmlspecialchars_decode($k['content'], ENT_QUOTES );
获取url上面的参数
$id= $this->input->get('id');
$_GET['id']; //原生php写法
调用父类方法
parent::fun();
$this->fun()