Question mark(?) is not working with Zend's where clause - zend-framework

Previously our zend 1.1 application was working with PHP 5.3 and Apache 2.2 versions and now we have upgraded our PHP to version 5.4 and Apache to 2.4
After this upgrade Zend's WHERE clause is not working with question mark (?) even it is not showing any error or warning. Example is given below:
$query = $db->select()
->from(array('users' => 'users'),
array('id' => 'id', 'email', 'fname'))
->where('email = ?', $email);
However it is working with without ? mark.
What is missing can anyone suggest because it is very critical for us.
Thanks

Like #TimFountain noted, turn on php errors.
Code should be:
$query = $db->select()
->from('users', array('id', 'email', 'fname'))
->where('email = ?', $email);
Or
$query = $db->select()
->from('users', array('id', 'email', 'fname'))
->where('users.email = ?', $email);
Or
$query = $db->select()
->from('users')
->columns(array('id', 'email', 'fname'))
->where('email = ?', $email);
Or
$query = $db->select()
->from(array('u' => 'users'), array('id', 'email', 'fname'))
->where('u.email = ?', $email);
Or :)
$query = $db->select()
->from(array('u' => 'users'))
->columns(array('id', 'email', 'fname'))
->where('u.email = ?', $email);
Resources
Zend Framework Manual

Related

How to use sum statements in Zend Framework1

How to use aggerate function in zend framework
$select = $this->select()->from(dailyusages, new Zend_Db_Expr("SUM(offPeakTotal)"));
Example
$select = new Zend_Db_Select($dbadapter);
$result = $select
->from(
'table_name',
array(
'offPeakTotalSum' => 'SUM(offPeakTotal)'
)
)
->query(Zend_Db::FETCH_ASSOC)
->fetch();
var_dump($result);

zend1 query converted to plain mysqli?

I have this zend framework 1 query which looks like this:
function getNumberOfNewPlayer() {
global $db, $start_date, $end_date;
$data = $db->select()
->from(array('c' => 'casino_israel.Network'),array('count(*) as total'))
->where('c.Date > ?', $start_date)
->where('c.Date < ?', $end_date)
->query()->fetch();
return $data['total'];
}
How would it look line in plain mysqli?Thanks!
$data = $db->select()
->from(array('c' => 'casino_israel.Network'),array('count(*) as total'))
->where('c.Date > ?', $start_date)
->where('c.Date < ?', $end_date);
echo $data->__toString();

how to use joins in Zend_Paginator_Adapter_DbSelect()

how can i replace below mysql query to ZF Zend_Paginator_Adapter_DbSelect()
query
$sql = "SELECT ps.phone_service_id,ps.phone_service_name,ps.phone_service_Duration,ps.phone_service_type,us.user_preferences_value,ps.user_id FROM phone_service ps,user_preferences us
WHERE us.phone_service_id = ps.phone_service_id
AND us.user_preferences_name = 'is_user_package_active'
AND ps.user_id =".$user_id;
i write this one but error occur could you please replace my query to equailent Zend_Paginator_Adapter_DbSelect()
$select = $DB->select()
->from(array('ps' => 'phone_service'
'us' => 'user_preferences'),
array('ps.phone_service_id', 'ps.phone_service_name','ps.phone_service_Duration','ps.phone_service_type','us.user_preferences_value')),
->where('us.phone_service_id = ?', 'ps.phone_service_id')
->where( 'us.user_preferences_name = ?', 'is_user_package_active')
->where( 'us.user_id = ?', $user_id)
;
I guess you want something like this:
$sel = $db->select();
$sel->from(array('p' => 'phone_service'))
->join(array('u' => 'user_preferences'), 'u.phone_service_id = p.phone_service_id')
->where('u.user_preferences_name = ?', 'is_user_package_active')
->where('p.user_id = ?', $user_id);

How to Use Multiple Conditions In An Update Statement With Zend_Db And QuoteInto

Using Zend Framework, is there a way to pass multiple conditions to an update statement using the quoteInto method? I've found some references to this problem but I'm looking for a supported way without having to extend Zend_Db or without concatenation.
$db = $this->getAdapter();
$data = array('profile_value' => $form['profile_value']);
$where = $db->quoteInto('user_id = ?', $form['id'])
. $db->quoteInto(' AND profile_key = ?', $key);
$this->update($data, $where);
References
http://blog.motane.lu/2009/05/21/zend_db-quoteinto-with-multiple-arguments/
http://codeaid.net/php/multiple-parameters-in-zend_db::quoteinto%28%29
You can use an array type for your $where argument. The elements will be combined with the AND operator:
$where = array();
$where[] = $this->getAdapter()->quoteInto('user_id = ?', $form['id']);
$where[] = $this->getAdapter()->quoteInto('key = ?', $key);
$this->update(array('value' => $form['value']), $where);
Since 1.8 you can use:
$where = array(
'name = ?' => $name,
'surname = ?' => $surname
);
$db->update($data, $where);
Just refreshing the above answer
$data = array('value' => $form['value']);
$where = array();
$where[] = $this->getAdapter()->quoteInto('user_id = ?', $form['id']);
$where[] = $this->getAdapter()->quoteInto('key = ?', $key);
$this->update($data, $where);

how to add another filter condition in zend framework query

This is my zend query
return $this->fetchRow($this->select()->where('name = ?', $geofence_name) );
and I want to add another filter in my query, because I want to check another condition.
please guide me.
For and where
$select = $db->select()
->from('products',
array('product_id', 'product_name', 'price'))
->where('price > ?', $minimumPrice)
->where('price < ?', $maximumPrice);
For or where
$select = $db->select()
->from('products',
array('product_id', 'product_name', 'price'))
->where('price < ?', $minimumPrice)
->orWhere('price > ?', $maximumPrice);