午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    codeigniter數(shù)據(jù)庫(kù)操作函數(shù)匯總
    來(lái)源:易賢網(wǎng) 閱讀:907 次 日期:2014-07-30 17:46:24
    溫馨提示:易賢網(wǎng)小編為您整理了“codeigniter數(shù)據(jù)庫(kù)操作函數(shù)匯總”,方便廣大網(wǎng)友查閱!

    網(wǎng)上倒是有不少codeigniter數(shù)據(jù)庫(kù)操作地介紹,這里做一個(gè)匯總.

    代碼如下:

    //查詢: 

    $query = $this->db_query(select * from table);

     ==================================

    //result() 返回對(duì)象數(shù)組

    $data = $query->result();

    //result_array() 返回?cái)?shù)據(jù)

    $data = $query->result_array();

    //row() 只返回一行對(duì)象數(shù)組

    $data = $query->row();

    //num_rows() 返回查詢結(jié)果行數(shù)

    $data = $query->num_rows();

    //num_fields() 返回查詢請(qǐng)求地字段個(gè)數(shù)

    $data = $query->num_fields();

    //row_array() 只返回一行數(shù)組

    $data = $query->row_array();

    //free_result() 釋放當(dāng)前查詢所占用地內(nèi)存并刪除關(guān)聯(lián)資源標(biāo)識(shí)

    $data = $query->free_result();

    /*

     ==================================

     插入操作

     ==================================

    */

    //上次插入操作生成地id

    echo $this->db->insert_id();

    //寫入和更新操作被影響地行數(shù)

    echo $this->db->affected_rows();

    //返回指定表地總行數(shù)

    echo $this->db->count_all('table_name');

    //輸出當(dāng)前地?cái)?shù)據(jù)庫(kù)版本號(hào)

    echo $this->db->version();

    //輸出當(dāng)前地?cái)?shù)據(jù)庫(kù)平臺(tái)

    echo $this->db->platform();

    //返回最后運(yùn)行地查詢語(yǔ)句

    echo $this->db->last_query();

    //插入數(shù)據(jù),被插入地?cái)?shù)據(jù)會(huì)被自動(dòng)轉(zhuǎn)換和過(guò)濾,例如:

    //$data = array('name' => $name, 'email' => $email, 'url' => $url);

    $this->db->insert_string('table_name', $data);

    /*

     ==================================

     更新操作

     ==================================

    */

    //更新數(shù)據(jù),被更新地?cái)?shù)據(jù)會(huì)被自動(dòng)轉(zhuǎn)換和過(guò)濾,例如:

    //$data = array('name' => $name, 'email' => $email, 'url' => $url);

    //$where = author_id = 1 and status = 'active';

    $this->db->update_string('table_name', $data, $where);

    /*

     ==================================

     選擇數(shù)據(jù)

     ==================================

    */

    //獲取表地全部數(shù)據(jù)

    $this->db->get('table_name');

    //第二個(gè)參數(shù)為輸出條數(shù),第三個(gè)參數(shù)為開始位置

    $this->db->get('table_name', 10, 20);

    //獲取數(shù)據(jù),第一個(gè)參數(shù)為表名,第二個(gè)為獲取條件,第三個(gè)為條數(shù)

    $this->db->get_where('table_name', array('id'=>$id), $offset);

    //select方式獲取數(shù)據(jù)

    $this->db->select('title, content, date');

    $data = $this->db->get('table_name');

    //獲取字段地最大值,第二個(gè)參數(shù)為別名,相當(dāng)于max(age) as nianling

    $this->db->select_max('age');

    $this->db->select_max('age', 'nianling');

    //獲取字段地最小值

    $this->db->select_min('age');

    $this->db->select_min('age', 'nianling');

    //獲取字段地和

    $this->db->select_sum('age');

    $this->db->select_sum('age', 'nianling');

    //自定義from表

    $this->db->select('title', content, date');

    $this->db->from('table_name');

    //查詢條件 where name = 'joe' and title = boss and status = 'active'

    $this->db->where('name', $name);

    $this->db->where('title', $title);

    $this->db->where('status', $status);

    //范圍查詢

    $this->db->where_in('item1', 'item2');

    $this->db->where_not_in('item1', 'item2');

    //匹配,第三個(gè)參數(shù)為匹配模式 title like '%match%'

    $this->db->like('title', 'match', 'before/after/both');

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機(jī)網(wǎng)站地址:codeigniter數(shù)據(jù)庫(kù)操作函數(shù)匯總
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)