2010年7月25日星期日

[fw-db] Column not found: 1054 Unknown column '00nk01' in 'where clause

I'm trying to do what ought to be the simplest of things, but for the past
few hours I've failed using various approaches.

I want to run the following function using a string as the $arg_sku:

public function productExists($arg_sku)
{
$query = $this->db->select()
->from('products', array('sku'))
->where('sku = ?', $arg_sku);
$result = $this->db->fetchOne($query);

if($result)
{
return true;
}else{
return false;
}
}

This is returning the following error:

Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message
'SQLSTATE[42S22]: Column not found: 1054 Unknown column '00nk01' in 'where
clause'' in C:\xampp\htdocs\sinfulthrills\lib\Zend\Db\Statement\Pdo.php:234
Stack trace: #0
C:\xampp\htdocs\sinfulthrills\lib\Zend\Db\Statement.php(300):
Zend_Db_Statement_Pdo->_execute(Array) #1
C:\xampp\htdocs\sinfulthrills\lib\Zend\Db\Adapter\Abstract.php(468):
Zend_Db_Statement->execute(Array) #2
C:\xampp\htdocs\sinfulthrills\lib\Zend\Db\Adapter\Pdo\Abstract.php(238):
Zend_Db_Adapter_Abstract->query('UPDATE `product...', Array) #3
C:\xampp\htdocs\sinfulthrills\lib\Zend\Db\Adapter\Abstract.php(604):
Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `product...', Array) #4
C:\xampp\htdocs\sinfulthrills\cron_scripts\products\library\Product.php(775):
Zend_Db_Adapter_Abstract->update('products', Array, 'sku = 00nk01') #5
C:\xampp\htdocs\sinfulthrills\cron_scripts\products\init\getss365products.php(441):
Product->updateProduct(Array) #6
C:\xampp\htdocs\sinfulthrills\cron_scripts\pr in
C:\xampp\htdocs\sinfulthrills\lib\Zend\Db\Statement\Pdo.php on line 234

If I echo the $query string that fails above and run it in phpMyAdmin it
returns the row I expect:

SELECT `products`.`sku` FROM `products` WHERE (sku = '00nk01')

I've tried:

->where('sku = ?', new Zend_Db_Expr($this->db->quote($arg_sku)));

And I've even tried just using straight sql:

$query = "SELECT `products`.`sku` FROM `products` WHERE (sku =
'".$arg_sku."')';
$result = $this->db->fetchOne($query);

No dice. I always get the same error. What do I have to do to get zend to
recognise the $arg_sku as an expression value and not a column name??

Please help because this is driving me mad!
--
View this message in context: http://zend-framework-community.634137.n4.nabble.com/Column-not-found-1054-Unknown-column-00nk01-in-where-clause-tp2301798p2301798.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: