Questions tagged [zend-db]

Database access component for the Zend Framework.

for PHP 5 includes a database access component, referred to as Zend\Db.

The Zend\Db component includes features such as:

  • Database connection factory class.
  • Adapter for multiple brands of database, closely matching the interface, and also supporting other non-PDO database interfaces such as mysqli and oci.
  • Simple query builder for generic SELECT syntax.
  • statement profiler and logger.
  • Table Data Gateway and Row Data Gateway classes. Together these are similar to the popular Active Record pattern.

Resources:

  1. Github repository
1092 questions
78
votes
14 answers

How to print exact sql query in zend framework ?

I have the following piece of code which i taken from model, ... $select = $this->_db->select() ->from($this->_name) ->where('shipping=?',$type) …
mymotherland
  • 7,968
  • 14
  • 65
  • 122
69
votes
6 answers

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?
xelurg
  • 4,294
  • 9
  • 35
  • 37
37
votes
9 answers

Registering Zend Database Adapter in Registry

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…
Stuart
  • 3,258
  • 4
  • 29
  • 39
26
votes
5 answers

last insert id with zend db table abstract

variable $tablemodel in an instance of a model which extends Zend_Db_Table_Abstract, if i do $tablemodel->insert($data) to insert data. Is there any method or property to get last insert id? regards
S L
  • 14,262
  • 17
  • 77
  • 116
26
votes
3 answers

Zend Framework: How to delete a table row where multiple things are true?

Normally, this would work for me: $db = Zend_Db_Table::getDefaultAdapter(); $where = $db->quoteInto('id = ?', $id); $db->delete('tablename', $where); but I have to match two ids. So I don't really know how to structure it. WHERE first_id = 'id1'…
Andrew
  • 227,796
  • 193
  • 515
  • 708
22
votes
7 answers

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.…
Thomaschaaf
  • 17,847
  • 32
  • 94
  • 128
22
votes
6 answers

How update a database table record in Zend?

I am using select like this and it is fetching record successfully: $table = new Bugs(); $select = $table->select(); $select->where('bug_status = ?', 'NEW'); $rows = $table->fetchAll($select); But Now I want to update same record. For example in…
Awan
  • 18,096
  • 36
  • 89
  • 131
22
votes
4 answers

How to use distinct in Zend Framework 2?

How can I use the distinct clause with Zend\Db\Sql\?
Emmanuel Gauthier
  • 531
  • 2
  • 4
  • 15
20
votes
4 answers

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…
Chris C
19
votes
4 answers

How does Zend\Db in ZF2 control transactions?

The ZF1 Zend_Db reference manual has an entire section on performing transactions. The ZF2 Zend\Db reference manual lacks any documentation on transactions. How do I perform transactions in ZF2? Example code would be helpful.
Greg.Forbes
  • 2,634
  • 4
  • 26
  • 29
16
votes
3 answers

Zend DB Select : ORDER BY FIELD('id',some_array) - how?

How would you write the following query in Zend framework? SELECT * FROM table_name ORDER BY FIELD(field_name, 'Small','Medium','Large'); I just need the "Order by" part :) Thanks!
srgb
  • 4,783
  • 6
  • 29
  • 45
16
votes
3 answers

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…
ezraspectre
  • 3,148
  • 5
  • 23
  • 28
16
votes
4 answers

Complex WHERE clause with Zend_Db using multiple AND OR operators

I want to generate this complex WHERE clause in Zend_Db: SELECT * FROM 'products' WHERE status = 'active' AND ( attribute = 'one' OR attribute = 'two' OR [...] ) ; I've tried…
jmbertucci
  • 8,194
  • 4
  • 50
  • 46
15
votes
2 answers

How can I access Database Adapter in ZF2 Field Set?

I have followed an example and would like to pass the Database adapter to a fieldset to create a drop down menu. The code below is how i call the fieldset. How can i access the database adapter in the BrandFieldset class? $this->add(array( …
Matt
  • 383
  • 1
  • 5
  • 20
15
votes
3 answers

Zend DB fetchAll(): where clause array with IN operator

I'm selecting records from a database using the equivalent of this query: SELECT * FROM reports WHERE user_id IN (3, 6, 22); The function calling fetchAll() has an argument that's an array of the user IDs, and this call works just fine: $resultSet…
Cyranix
  • 337
  • 1
  • 4
  • 11
1
2 3
72 73