zend-db

How to create WHERE IN clause with Zend_Db_Select

So I am trying to accomplish something like this: SELECT * FROM table WHERE status_id IN (1,3,4); using Zend_Db_Select... can't find how to do it :( Is it at all possible? ...

how to get last inserted Id of a Sqlite database using Zend_Db

I'm trying to fetch the last inserted row Id of a Sqlite DB in my PHP application. I'm using Zend Framework's PDO Sqlite adapter for database handling. the lastInsertId() method is supposed to give me the results, but it wouldn't. In PDO documentation in php.net I read that the lastInsertId() might not work the same on all databases. but...

Zend_Db is ignoring my default field values!

Hi, I'm using Zend Framework 1.7 with a MySQL 5.0 database for a project I'm doing. Part of the system is a longish form that asks a user for various dates (in dd/mm/yyyy format) as well as some integer fields. In my MySQL table, all these fields have a default of null. When I come to save the form data with a function in my model (whic...

How to get Column Name With Zend DB

How to get Column Name With Zend DB ...

How do I add more than one row with Zend_Db?

I have an array with information which looks more or less like this: $data[] = array('content'=>'asd'); $data[] = array('content'=>'asdf'); And I want to add both entries into the Database. $db->insert('table', $data); does not add both entries. What am I doing wrong? Do I have to use Zend_ Db_Table? $data = array('content'=>'asdf...

Zend_Db Question... updating an incrementor

Should this work? (increment the login count?) // update the login count $data = array( 'logins' => 'logins + 1' ); $n = $db->update('users', $data, 'user_id = '.$_userId); ...

Example of a Multi Condition Delete with Zend framework

Can someone give me an example of how I would delete a row in mysql with Zend framework when I have two conditions? i.e: (trying to do this) "DELETE FROM messages WHERE message_id = 1 AND user_id = 2" My code (that is failing miserably looks like this) // is this our message? $condition = array( 'message_id = ' =>...

Registering Zend Database Adapter in Registry

Hi I am looking to register a reference to the main Database Adapter in the Registry during Bootstrapping so it can be used elsewhere in my site (specifically the Authorisation action). I have implemented an ugly fix where i create a Database Table object and call the getAdapter() method on it and pass through that. However, this is a ...

Integrity constraint violation in Zend_db

Hi - I have the following code: $selectColumns= array('user_id.user_email', 'user_details.first_name', 'user_details.last_name', 'user_details.zip', 'user_details.store_id'); $result = $handle->select()->from('user_id') ->where('uid=?', $uid) ->columns($select...

Is there a way to get the number of records from a query with Zend-framework?

Given my generic select below, is there a way to get the number of records returned from a query with Zend Framework? $row++ in a loop is not acceptable for my solution as I am using paging (though its not in my sample). I also DO NOT want to add another query with "Count(*)". $query = "Select * from Users where active = 1"; $stmt = $...

Zend DB Framework examine query for an update

So you can use something like this: $query = $db->select(); $query->from('pages', array('url')); echo $query->__toString(); to examine the sql that the Zend Db Framework is going to use for that SELECT query. Is there an equivilent way to view the SQL for an update? $data = array( 'content' => stripslashes(htmlspecialchars_de...

zend not using columns, and selecting everything

Hi, I have the following code $result = $handle->select()->from('store_details') ->where('store_details.store_id=?', $id) ->columns('store_details.store_name'); //->query(ZEND_DB::FETCH_OBJ); However, when I run it, the entire row is selecte...

Sort MPTT resultset into a multidimensional array PHP

I have been experimenting with the Modified Pre-Order Tree Traversal Pattern, my test case code is returning the results as expected however I am having trouble converting the 2D array into a multi-dimensional array to present it. Here is an example of a 3 level menu result, I need to convert this into a multi-dimensional array so that ...

Zend selects all columns

In the following code: $selectColumns= array('user_id.user_email', // inner join the data from user_id and user_details 'user_details.first_name', 'user_details.last_name'); $result = $handle->select()->from('user_id', $selectColumns) ->where('user_id.uid=?', $uid) ...

retrieve last updated column in mysql

Hi, I have a MySQL query that goes as follows (using Zend_Db): $sql = $handle->quoteInto("UPDATE board SET rank=rank+1 WHERE post_id=?", $postid); $handle->query($sql); (Rank isn't an auto-incrementing PK). I would like to now retrieve the value of rank without preforming another query. I've tried $handle->lastInsertId(); but it doe...

Zend_DB_Select - How to write this SQL Statement

Good Morning, i have some Trouble with the Zend Framework and Zend_DB_Select, i want to use this (Working) SQL Statement as Zend DB Select Statement : select oslang from oslang, os where oslang.oslang_id = os.oslang_id and ossubversion_id = 1 I have tryed to following but it doenst work : try { $select = $this->_db->...

MySQL random rows sorted by a column name

Original Question: I am currently using Zend Framework with Zend_Db_*, and I am selecting three random rows from a table: $category->getTable()->select()->order(new Zend_Db_Expr('RAND()'))->limit('3') Where $category is a Zend_Db_Table_Row. I would like to grab three random rows, but have those three rows ordered by the column named ...

Zend: Two Objects, one Row.

I've recently started using Zend Framework (1.8.4), to provide admin tools for viewing the orders of a shopping cart site. What I'd like to do is to efficiently create multiple model (Zend_Db_Table_Row_Abstract) objects from a single database result row. The relationship is simple: an Order has one Customer (foreign key order_custid...

Zend Framework Db Select Join table help

I have this query: SELECT g.title, g.asin, g.platform_id, r.rank FROM games g INNER JOIN ranks r ON ( g.id = r.game_id ) ORDER BY r.rank DESC LIMIT 5` Now, this is my JOIN using Zend_Db_Select but it gives me array error $query = $this->select(); $query->from(array('g' => 'games'), array()); $query->j...

In Zend_Auth, can I get a domain-model User object instead of stdClass?

Hi there, While working on the login part of an application, I find myself running into an issue: My model is based on Active Record, by extending Zend_Db_Table_Row objects. Whenever I have to deal with a user, I'd want to do this through the User object (being an extended table row). However, Zend_Auth_Adapter_DbTable::getResultRowO...