我正在使用zend框架。 我想定义产品名称是否存在,如果没有,则插入产品名称。
我在控制器中使用此代码
$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 :(得分: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";
}
i user current()函数,当$ productresult没有任何值时返回null值...