2010-04-10 23 views
0

代碼點火器,你可以鍵入:如何返回當前對象?

$query = $this->db->query("YOUR QUERY"); 

foreach ($query->result() as $row) 
{ 
    echo $row->title; 
    echo $row->name; 
    echo $row->body; 
} 

我猜測,查詢方法返回它的一部分的對象。我對麼?

如果我是,你怎麼輸入它返回對象的那一行?

所以我想知道它是如何看起來像在上面的代碼的功能的查詢方法。

public function query($sql) { 
    // some db logic here with the $sql and saves the values to the properties (title, name and body) 

    return X 
} 

換句話說,X應該是什麼?

回答

1

該函數位於/system/database/DB_driver.php:244

在一個成功的查詢,它返回一個新的DB結果對象的數據庫驅動程序(可能)在您的應用程序的數據庫配置設置。

例如:CI_DB_mysql_result(位於/system/database/drivers/mysql/mysql_result.php);

換句話說,X應該是什麼?

$driver   = $this->load_rdriver(); 
$RES   = new $driver(); 
$RES->conn_id = $this->conn_id; 
$RES->result_id = $this->result_id; 

從DB_driver.php:366

2

我沒有帶讀笨的源代碼,但它可能是合理的假設,$query是某種表示分貝結果類的,所以它很可能是一個return $this;

這也可能是一些如:return new Db_ResultSet($data)或類似。