亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Array Array Helper Benchmarking Benchmarking Class Caching Caching Driver Calendaring Calendaring Class CAPTCHA CAPTCHA Helper Config Config Class Cookie Cookie Helper Database Connecting to your Database Custom Function Calls Database Caching Class Database Configuration Database Forge Class Database Metadata Database Quick Start: Example Code Database Reference Database Utility Class DB Driver Reference Generating Query Results Queries Query Builder Class Query Helper Methods Transactions Date Date Helper Directory Directory Helper Download Download Helper Email Email Class Email Helper Encrypt Encrypt Class Encryption Encryption Library File File Helper File Uploading File Uploading Class Form Form Helper Form Validation Form Validation FTP FTP Class Functions compatibility_functions common_functions HTML HTML Helper HTML Table HTML Table Class Image Manipulation Image Manipulation Class Inflector Inflector Helper Input Input Class Javascript Javascript Class Language Language Class Language Helper Loader Loader Class Migrations Migrations Class Number Number Helper Output Output Class Pagination Pagination Class Path Path Helper Security Security Class Security Helper Session Session Library Shopping Cart Shopping Cart Class Smiley Smiley Helper String String Helper Template Parser Template Parser Class Text Text Helper Trackback Trackback Class Typography Typography Class Typography Helper Unit Testing Unit Testing Class URI URL User Agent XML XML-RPC and XML-RPC Server Zip Encoding Zip Encoding Class XML-RPC and XML-RPC Server Classes XML Helper User Agent Class URL Helper URI Class
characters

下面的頁(yè)面包含示例代碼,顯示如何使用數(shù)據(jù)庫(kù)類(lèi)。要獲得完整的細(xì)節(jié),請(qǐng)閱讀描述每個(gè)功能的各個(gè)頁(yè)面。

初始化數(shù)據(jù)庫(kù)類(lèi)

下面的代碼根據(jù)配置設(shè)置:

$this->load->database();

一旦加載,類(lèi)就可以使用了,如下所述。

注意:如果您的所有頁(yè)面都需要數(shù)據(jù)庫(kù)訪(fǎng)問(wèn),您可以自動(dòng)連接。見(jiàn)連接詳細(xì)信息。

具有多個(gè)結(jié)果的標(biāo)準(zhǔn)查詢(xún)(對(duì)象版本)

$query = $this->db->query('SELECT name, title, email FROM my_table');foreach ($query->result() as $row){
        echo $row->title;
        echo $row->name;
        echo $row->email;}echo 'Total Results: ' . $query->num_rows();

上面的result()函數(shù)返回一個(gè)對(duì)象數(shù)組。例如:$ row-> title

具有多個(gè)結(jié)果的標(biāo)準(zhǔn)查詢(xún)(數(shù)組版本)

$query = $this->db->query('SELECT name, title, email FROM my_table');foreach ($query->result_array() as $row){
        echo $row['title'];
        echo $row['name'];
        echo $row['email'];}

上面的result_array()函數(shù)返回一個(gè)標(biāo)準(zhǔn)數(shù)組索引數(shù)組。例如:$ row'title'

具有單一結(jié)果的標(biāo)準(zhǔn)查詢(xún)

$query = $this->db->query('SELECT name FROM my_table LIMIT 1');$row = $query->row();echo $row->name;

上面的row()函數(shù)返回一個(gè)對(duì)象。例如:$ row-> name

具有單一結(jié)果的標(biāo)準(zhǔn)查詢(xún)(陣列版本)

$query = $this->db->query('SELECT name FROM my_table LIMIT 1');$row = $query->row_array();echo $row['name'];

上面的row_array()函數(shù)返回一個(gè)數(shù)組。例如:$ row'name'

標(biāo)準(zhǔn)插入

$sql = "INSERT INTO mytable (title, name) VALUES (".$this->db->escape($title).", ".$this->db->escape($name).")";
$this->db->query($sql);echo $this->db->affected_rows();

查詢(xún)生成器查詢(xún)

查詢(xún)構(gòu)建器模式為您提供了一種檢索數(shù)據(jù)的簡(jiǎn)化方法:

$query = $this->db->get('table_name');foreach ($query->result() as $row){
        echo $row->title;}

上面的get()函數(shù)從提供的表中檢索所有結(jié)果。查詢(xún)生成器類(lèi)包含完整的函數(shù)處理數(shù)據(jù)。

查詢(xún)生成器插入

$data = array(        
    'title' => $title,        
    'name' => $name,        
    'date' => $date);
$this->db->insert('mytable', $data);  // Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
Previous article: Next article: