2015-09-21 24 views
0

我正在使用zend框架。 我想定義產品名稱是否存在,如果沒有則插入產品名稱。如何在zend中使用db-table在數據庫中定義表記錄是否存在或不存在

我在控制器

$this->product_tbl = new Application_Model_DbTable_Producttbl(); 

$product_name = 'mobile'; 

$productresult = $this->product_tbl->fetchRow($this->product_tbl->select()->where('product_name ='.$product_name)); 

if(!$productresult){ 

         // do when productresult is null 

} 

Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'mobile' in 'where clause' 

我的問題是如果product_name未找到則顯示一個簡單的消息「行未找到」

+0

你能否提供你的表的結構......'product_name'和'mobile'都是列嗎? – coolguy

+1

謝謝,但我解決了我的問題.. –

+1

'product_name'是表的字段,$ proudct_name是可變的 –

回答

1
$this->product_tbl = new Application_Model_DbTable_Producttbl(); // project db table 

$product_name = 'mobile'; // project_name variable declare and store value 'mobile' 

$productresult = $this->product_tbl->fetchAll($this->product_tbl->select()->where('product_name = ?', $product_name)); // Fetch result and store in $productresult 

$row = $productresult->current(); // set current() 

if($row == NULL){ 

     echo "row is null"; 
} 

我用戶當前()函數使用此代碼當$ productresult沒有任何值時返回空值...

相關問題