ci手冊:http://codeigniter.org.cn/user_guide/
CI操作數(shù)據(jù)庫
$this->load->database();//必須先載入數(shù)據(jù)庫
//$dsn = 'dbdriver://root:root@localhost/cnmobi';
//$this->load->database($dsn);
$query = $this->db->get('form_1_liuyan')->result();
查詢指定字段數(shù)據(jù)
$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); //"中文"
轉(zhuǎn)碼問題狐榔,將html字符串轉(zhuǎn)成html實(shí)體
$k['content'] = htmlspecialchars_decode($k['content'], ENT_QUOTES );
獲取url上面的參數(shù)
$id= $this->input->get('id');
$_GET['id']; //原生php寫法
調(diào)用父類方法
parent::fun();
$this->fun()