zend-db

Zend Framework Db Select Join table help

杀马特。学长 韩版系。学妹 提交于 2019-11-30 17:02:02
问题 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->join(array('r' => 'ranks'), 'g.id = r.game_id', array('g.title', 'g.asin', 'g.platform_id', 'r.rank')); $query->order('r.rank DESC'); $query->limit($top); $resultRows = $this->fetchAll($query);

Zend Framework 2 Sql Select with OR and AND

◇◆丶佛笑我妖孽 提交于 2019-11-30 07:10:38
I want to make this query using Zend\Db\Sql\Select: SELECT table1.* FROM table1 INNER JOIN table2 ON table1.columnA = table2.columnB INNER JOIN table3 ON table1.columnC = table3.columnD WHERE (table2.column2 = 2 or table3.column3 = 3) and table1.column1 = 1 ORDER BY table1.columnE ASC LIMIT 1 I have this code so far: /*@var $db Adapter */ $db = $this->getServiceLocator()->get('db'); $sql = new Sql($db); $select = $sql->select(); $select->from('table1'); $select->join('table2','table1.columnA = table2.columnB',array()); $select->join('table3','table1.columnC = table3.columnD',array()); $select-

Zend Framework Db Select Join table help

旧街凉风 提交于 2019-11-30 05:49:19
问题 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->join(array('r' => 'ranks'), 'g.id = r.game_id', array('g.title', 'g.asin', 'g.platform_id', 'r.rank')); $query->order('r.rank DESC'); $query->limit($top); $resultRows = $this->fetchAll($query);

Zend Select NOT IN

馋奶兔 提交于 2019-11-30 04:22:35
问题 I have two tables with related data, and I want to select all the records from one table which do not exist in the other table, plus some other criteria on the related table, as follows (123 is just for illustration purposes): TABLE A ID SOMETHING TABLE B TABLE_A_ID TABLE_C_ID SOMETHING My query, run directly against the data, would be as follows SELECT A.SOMETHING FROM A WHERE A.ID NOT IN ( SELECT B.TABLE_A_ID AS ID FROM B WHERE TABLE_C_ID = 123 ); How can I run this in Zend? 回答1: You can

Zend Framework 2 Paginator + TableGateway

你。 提交于 2019-11-30 00:09:13
问题 How to use the database mapper with the paginator? I'm having a bit trouble understanding how I implement the DbSelect paginator using the code below (right now it's using the Iterator adapter which doesn't work for ResultSets). From what I can tell it's not as straight forward as I would have hoped. DbSelect is expecting a Zend\Db\Sql\Select and an adapter. The adapter is a non issue and can be retrieved with: $this->newsContents()->getAdapter() but I'm having trouble getting a Select object

Zend DB Framework examine query for an update

我们两清 提交于 2019-11-29 20:39:11
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_decode($content)) ); $n = $db->update('pages', $data, "url = '".$content."'"); ?? Bill Karwin Use Zend_Db_Profiler to capture and report SQL statements: $db->getProfiler()->setEnabled(true); $db->update( ... ); print $db->getProfiler()->getLastQueryProfile()->getQuery();

Zend Framework 2 Sql Select with OR and AND

眉间皱痕 提交于 2019-11-29 09:06:22
问题 I want to make this query using Zend\Db\Sql\Select: SELECT table1.* FROM table1 INNER JOIN table2 ON table1.columnA = table2.columnB INNER JOIN table3 ON table1.columnC = table3.columnD WHERE (table2.column2 = 2 or table3.column3 = 3) and table1.column1 = 1 ORDER BY table1.columnE ASC LIMIT 1 I have this code so far: /*@var $db Adapter */ $db = $this->getServiceLocator()->get('db'); $sql = new Sql($db); $select = $sql->select(); $select->from('table1'); $select->join('table2','table1.columnA

Zend Enable SQL Query logging

你。 提交于 2019-11-29 07:15:32
I am using this to retrieve the database connection atm. $db = Zend_Db_Table::getDefaultAdapter(); I do set this up in my config like this: resources.db.adapter = pdo_mysql resources.db.isDefaultTableAdapter = true resources.db.params.host = localhost resources.db.params.username = root resources.db.params.password = password resources.db.params.dbname = db resources.db.params.profiler.enabled = true resources.db.params.profiler.class = Zend_Db_Profiler I would like to output everything to a sql.log for example. Is this possible to apply on the default adapter? for example through the settings

connecting to two different databases with Zend Framework

一个人想着一个人 提交于 2019-11-29 06:21:11
I have here a medium sized intranet site which is written entirely in Zend FW. The database for the intranet is located on another server. Now I need to extend the intranet with some new functionality. In order to do this I need to connect to another database on the same server (and same DBMS). The question is now: What is the best way to do this? Should I create a new Zend_Config object and a new Zend_Db_Adapter? Or should I use the existing one and try with the "use otherdbname;" statement to connect within the same session to the new database? Or is there an even better way to do it? One

Complex WHERE clause with Zend_Db using multiple AND OR operators

妖精的绣舞 提交于 2019-11-29 03:24:47
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 this: $select->from('product'); $select->where('status = ?', $status); $select->where('attribute = ?', $a1); $select->orWhere('attribute = ?', $a2); and that produced: SELECT `product`.* FROM `product` WHERE (status = 'active') AND (attribute = 'one') OR (attribute = 'two') ; I did figure out one method of making this work but I felt it was sort of 'cheating' by using PHP to combine the "OR" clauses first and then combine