我试图查看查询,执行它并获得结果。 这是我的尝试:
$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'";
)代码被注释时会发生这种情况:
当没有评论时会发生这种情况:
答案 0 :(得分: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)
{
//....
}
答案 1 :(得分:0)
尝试:
$db = Zend_Db_Table::getDefaultAdapter();
$row = $db->fetchRow("SELECT * FROM order_products_names where order_id = '". $last_id . "'");
echo $row['names'];