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();
Related
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
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);
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);
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);
I'm just wondering what the syntax is to do a db select in Zend Framework where two values are true. Example: I want to find if a user is already a member of a group:
$userId = 1;
$groupId = 2;
$db = Zend_Db_Table::getDefaultAdapter();
$select = new Zend_Db_Select($db);
$select->from('group_members')
->where('user_id = ?', $userId); //Right here. What do I do about group_id?
$result = $select->query();
$resultSet = $result->fetchAll();
You can use multiple where clauses which will be ANDed together by default:
$select->from('group_members')
->where('user_id = ?', $userId)
->where('group_id = ?', $groupId);
Just In case someone wants to add an OR condition to a select with multiple params
$select = $db->select()
->from('products',
array('product_id', 'product_name', 'price'))
->where('price < ?', $minimumPrice)
->orWhere('price > ?', $maximumPrice);
For more view the Zend Select manual Docs: zend.db.select