zend-db-select

Translating a query to use Zend_Db_Select

怎甘沉沦 提交于 2020-01-12 03:49:05
问题 I'm having some problems translating this query to use ZF's Zend_Db_Select : SELECT b.id, b.title, b.description FROM memberships AS m JOIN blogs AS b ON b.id = m.blog_id WHERE m.user_id = ? ORDER BY m.created LIMIT 0, 30 (this query works and returns results) Memberships is a link table between blogs and users . It's a simple | id | blog_id | user_id | affair. Here's what I have so far: // $table = Zend_Db_Table instance, $id = a user id $select = $table->select() ->from(array('m' =>

setIntegrityCheck in Zend Selects with joins

落爺英雄遲暮 提交于 2020-01-01 02:33:05
问题 I was looking at some questions that ask how to do joins in Zend Framework queries, but the answer is always something like "just do setIntegrityCheck(FALSE) ". My question is: why do I need to do this? It seems to me disabling "integrity checks" is not the proper way of making this work. In my particular case, I'm using a MySQL database with some InnoDB tables with foreign keys, so for example: CREATE TABLE IF NOT EXISTS `tableA` ( `id` CHAR(6), `name` VARCHAR(255), PRIMARY KEY (`id`) )

How to use GROUP_CONCAT with Zend Framework?

本秂侑毒 提交于 2019-12-30 03:31:05
问题 Assume that I have a table : students ______________________________________________________ |id | name | school | class | ______________________________________________________ | 1 | John | ABC | C1 | | 2 | Jack | ABC | C1 | | 3 | Anna | ABC | C1 | | 4 | Peter | DEF | D1 | | 5 | Alex | ABC | C2 | | 6 | Bryan | ABC | C2 | | 7 | David | ABC | C2 | | 8 | Cristian | DEF | D1 | _______________________________________________________ Using this query : SELECT a.class,GROUP_CONCAT(a.name) as names

Zend 2: SQLSRV: $prepareParams is not being set

老子叫甜甜 提交于 2019-12-20 04:26:14
问题 Can somebody explain me where the ->setPrepareParams(array $prepareParams) is called in Zend\Db\Adapter\Driver\Sqlsrv\Statement.php? Specifically, when I used this: $this->tableGateway->select(array("Personalnummer = $personalnumber")); It worked. But when I used this: $this->tableGateway->select(array("Personalnummer" => $personalnumber)); It did not work. I tried to debug this and found that the params were not being set with my second method. 回答1: It is a public method so it is up to the

Issue with quoting of IS, NULL, NOT, !, and other reserved strings in ON conditions of JOIN clauses in Zend Framework 2

帅比萌擦擦* 提交于 2019-12-11 17:57:43
问题 I have an SQL statement, that selets sport classes/courses ( courses ) with their trainers ( trainers ) over an association table ( courses_trainers ). Since some courses have multiple trainers, I use the GROUP_CONCAT(...) function to get the trainer names into one field. Some trainers rows are empty or NULL , so I add a trainers.name IS NOT NULL and a trainers.name != "" condition to the ON clause of the trainers JOIN : SQL statement SELECT courses.id AS id, GROUP_CONCAT(DISTINCT trainers

Zend Framework: Re-use WHERE clause returned from Zend_Db_Select::getPart()

人走茶凉 提交于 2019-12-10 19:59:57
问题 I have a SELECT object which contains a WHERE. I can return the WHERE using getPart(Zend_Db_Select::WHERE) , this returns something like this: array 0 => string "(clienttype = 'agent')" 1 => string "AND (nextpayment < (NOW() - INTERVAL 1 DAY))" This array seems pretty useless as I cannot do this with it $client->update(array("paymentstatus" => "lapsed"), $where); Or even put it into another SELECT object. Is there a way of getting a more useful representation of the WHERE statement from the

GROUP_CONCAT with JOINLEFT in Zend Db Select

橙三吉。 提交于 2019-12-10 04:12:08
问题 Assuming that I have 2 tables articles id title 1 Article 1 2 Article 2 Images id article_id image 1 1 a.png 2 1 b.png 3 2 c.png 4 2 d.png All that I want is retreive all articles with their images. For example: article_id title images 1 Article 1 a.png, b.png 2 Article 2 c.png, d.png How could I do that with Zend_Db_Select? I tried something like this but had no luck: $select = $this->getDbTable()->select()->setIntegrityCheck(false)->distinct(); $select->from(array('a'=>'articles')) -

Zend DB Selecting constants - columns that do not exist in table

旧城冷巷雨未停 提交于 2019-12-06 19:31:31
问题 I'm trying to do this query using Zend DB select but I'm not able to do so This is the sql query select shopping_id,shopping_details,"friend" as type from shopping Notice here how I'm specifying "friend" as type and friend is not a column in the shopping table. Now how do I do this in Zend. I have tried this but it gives me an error saying "sh.friend Column does not exist" $select->from(array('sh'=>'shopping'),array('shopping_id','shopping_details','"friend" as type'); Any help will be

How can I join a subquery using Zend_Db_Select

纵饮孤独 提交于 2019-12-05 18:01:36
问题 How would I construct this query using Zend_Db_Select? : SELECT users.user_id, email_address, t1.value as 'languages' FROM users LEFT JOIN ( SELECT user_id , field_id , GROUP_CONCAT(value SEPARATOR ',') AS value FROM user_multivalued WHERE field_id=25 GROUP BY user_id, field_id) t1 ON t1.user_id = users.users_id WHERE list_id = 45 回答1: $user_multivalued = $db ->select() ->from('user_multivalued', array( 'user_id', 'field_id', new Zend_Db_Expr("GROUP_CONCAT(value SEPARATOR ',') AS value") )) -

GROUP_CONCAT with JOINLEFT in Zend Db Select

被刻印的时光 ゝ 提交于 2019-12-05 04:57:44
Assuming that I have 2 tables articles id title 1 Article 1 2 Article 2 Images id article_id image 1 1 a.png 2 1 b.png 3 2 c.png 4 2 d.png All that I want is retreive all articles with their images. For example: article_id title images 1 Article 1 a.png, b.png 2 Article 2 c.png, d.png How could I do that with Zend_Db_Select? I tried something like this but had no luck: $select = $this->getDbTable()->select()->setIntegrityCheck(false)->distinct(); $select->from(array('a'=>'articles')) ->joinLeft(array('i'=>'images'),'i.article_id=a.id',array('images'=> new Zend_Db_Expr('GROUP_CONCAT(i.image)'))