2017-07-12 38 views
-1

此查詢順利運行於phpmyadmin。但在我的項目中,這不是查詢。php pdo此查詢未運行,但它在phpmyadmin上運行順利

$sql = 'SELECT p.est_id,p.sec_plan_number,p.plot_plan_number, 
        (select policyno from tbl_plot_statusd where est_id=p.est_id 
        and sec_plan_number=p.sec_plan_number and plot_plan_number=p.plot_plan_number 
        and op_id=ps.op_id) as policyno, (select nic from tbl_plot_statusd 
        where est_id=p.est_id and sec_plan_number=p.sec_plan_number 
        and plot_plan_number=p.plot_plan_number and op_id=ps.op_id) as nic 
        FROM `tbl_plot` p left join tbl_plot_status ps on p.est_id=ps.est_id 
        and p.sec_plan_number = ps.sec_plan_number and p.plot_plan_number=ps.plot_plan_number 
        where ps.status_type_code=2 and ps.is_last_status=1 and p.isactive=1 
        order by ps.est_id,ps.sec_plan_number,abs(ps.plot_plan_number)'; 
foreach ($db->query($sql) as $d) 
+0

的foreach爲什麼會出現? –

+0

@AlivetoDie'PDOStatement'實現了'Traversable',因此可以在'foreach'中使用。 – Phil

+2

你在標題中提到了一個例外。它是什麼? – Phil

回答

0

嘗試

$query = $db->query($sql); 
foreach ($query->fetchAll() as $d) 
{ 

} 
+0

它也不工作..沒有任何錯誤顯示。 –

+0

什麼是錯誤? –

+1

@HarshaPriyalal當你運行你的代碼時,你會得到什麼錯誤。你還可以多一些代碼(完整代碼)以及你的異常嗎? –