2014-04-15 73 views
0

我試圖在查看查詢,執行它並獲得結果。 這是我的嘗試:如何在Zend 1中創建查詢並從查詢中獲取結果?

$last_id = $_COOKIE['last_id']; 
//if (isset($last_id)){ 
$db = new Zend_Db_Table('order_products_names'); //the table name 
$query = "select * from order_products_names where order_id = '$last_id'"; 
$query = $db->query($query); 
while ($row = $query->fetch()) { 
    echo $row['names']; 
} 

顯然它不起作用。有人可以幫我弄這個嗎 ? 我也試過這個版本:

$db = new Zend_Db_Adapter_Pdo_Mysql(array(
       'host'  => 'localhost', 
       'username' => 'lunchbox_live', 
       'password' => 'xxxxxxxxxxxx', 
       'dbname' => 'order_products_names', 
       'adapterNamespace' => 'MyProject_Db_Adapter' 
)); 
$last_id = $_COOKIE['last_id']; 
$dbAdapter = Zend_Db_Table::getDefaultAdapter(); 
$query = $dbAdapter->query("select * from order_products_names where order_id = '$last_id'"; 

這發生在這行代碼($query = $dbAdapter->query("select * from order_products_names where order_id = '$last_id'";)的評論: enter image description here 和發生這種情況時,不評論說: enter image description here

+0

誰知道zend? – Chester

+0

有沒有你在$ dbAdapter中的東西? – doydoy44

+0

嗨再次@ doydoy44我更新了我的文章,請查看 – Chester

回答

0

嘗試:

$db = Zend_Db_Table::getDefaultAdapter(); 
$row = $db->fetchRow("SELECT * FROM order_products_names where order_id = '". $last_id . "'"); 
echo $row['names']; 
0

這不是一個好辦法做事情,但只是爲了回答你的問題,嘗試這樣的事情:

$db = new Zend_Db_Adapter_Pdo_Mysql(array(
       'host'  => 'localhost', 
       'username' => 'lunchbox_live', 
       'password' => 'xxxxxxxxxxxx', 
       'dbname' => 'order_products_names', 
       'adapterNamespace' => 'MyProject_Db_Adapter' 
)); 

$last_id = $_COOKIE['last_id']; 
$stmt = $db->query("select * from order_products_names where order_id = ?", array($last_id)); 
$products = $stmt->fetchAll(); 

foreach($products as $product) 
{ 
//.... 
} 
+0

你可以邀請我聊天嗎? – Chester

相關問題