Hector is right, update() quotes identifiers you use in the keys of
the $data array. The usage Hector shows is correct.
insert() also quotes identifiers for columns:
$data = array('default' => 1);
$db->insert('my_table', $data);
But Zend_Db does not automatically quote or delimit elements in a
$where clause. It would be too much work to parse the full range of
syntax you might use in that clause. So you are responsible for
quoting values and delimiting identifiers yourself. Zend_Db provides
a method quoteIdentifier(). Here's how I'd write your fetchall example:
$col_default = $db->quoteIdentifier('default');
$sql = <<GO
SELECT * FROM types_appointment
WHERE doctor_id = {$doctorid} AND {$col_default} = 1
GO;
You can do something similar for a $where clause for update() or
delete().
Don't try to use quote() or quoteInto() for delimiting identifiers,
they are meant for quoting values, not identifiers.
Regards,
Bill Karwin
On Sep 3, 2010, at 7:38 AM, Hector Virgen wrote:
Zend_Db_Adapter_Abstract#update() will automatically quote
identifiers in the $data array (aka $bind), but not the $where
array. Have you tried without manually quoting the $data array?
$data = array('default' => 0);
$where = array("{$db->quoteIdentifier('default')} = ?" => 1);
$db->update('my_table', $data, $where);
--
Hector Virgen
Sr. Web Developer
Walt Disney Parks and Resorts Online
http://www.virgentech.com
On Fri, Sep 3, 2010 at 6:54 AM, debussy007 <debussy...@gmail.com>
wrote:
By the way, with fetchAll I got it working :
function getDefaultTypeAppointment($doctorId) {
$db = Zend_Registry::get(My_Constant_App::REG_DB_ADAPTER);
$sql = 'SELECT * FROM types_appointment ' .
'WHERE doctor_id = ' . $doctorId . ' AND `default` =
1';
return $db->fetchRow($sql);
}
I have only problems with update above :-(
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/Quote-reserved-keywords-tp2525558p2525707.html
Sent from the Zend Framework mailing list archive at Nabble.com.