zend-db

How to enable SQL output to log file with Zend_Db?

China☆狼群 提交于 2019-12-02 07:40:09
问题 I wonder if this possible with Zend_Db, but I am looking for something like SQL query logging similar to how Hibernate does it, where it shows you what SQL it generates in the log file. 回答1: You can use Zend_Db_Profiler for this task. Tutorial Zend Framework 1.6 with Profiler and FireBug 来源: https://stackoverflow.com/questions/2894077/how-to-enable-sql-output-to-log-file-with-zend-db

Zend Framework: How to concatenate two columns and still use fetchPairs()?

心不动则不痛 提交于 2019-12-02 00:02:41
问题 I have a form with a select element that I need to populate with values from a database. Specifically, the name and id of the current users. The fetchPairs() function works great for this! However, I need to concatenate the value from the first_name column and the last_name column and display this as the option label. Is there a way to do it and still use fetchPairs() ? If not, how can I achieve the same result? Here's an excerpt of the code that is currently working: <?php // excerpt class

Zend Framework 2: Getting an ordered SQL call

 ̄綄美尐妖づ 提交于 2019-12-01 23:23:18
问题 I've been trying to get an order ASC/DESC call for a field (let's say craeted), and I can't seem to figure out how to do it in ZF2. Where am I going wrong..? namespace Todo\Model; class TodoTable extends AbstractTableGateway { public function __construct(Adapter $adapter) { $this->adapter = $adapter; $this->resultSetPrototype = new ResultSet(); $this->resultSetPrototype->setArrayObjectPrototype(new Todo()); $this->initialize(); } public function fetchAll() { $resultSet = $this->select(array(

mysql_real_escape_string with Zend

安稳与你 提交于 2019-12-01 17:54:33
问题 I am developing a web application using zend framework. For select statements I have used following way. Ex: public function getData($name) { $sql = "SELECT * from customer where Customer_Name = '$name'"; return $this->objDB->getAdapter()->fetchAll ($sql); } This works fine. But If I send customer name as : colvin's place , The query fail. And I know it's because of the single quote. Earlier I used addslashes PHP function. But I saw it is not a good way to do this. This time I used mysql_real

Zend Framework: How to retrieve the id of the last inserted row?

岁酱吖の 提交于 2019-12-01 14:15:02
问题 I'm inserting a new row into my database with this code: $data = array( 'key' => 'value' ); $this->getDbTable()->insert($data); How can I get the row id of the this row that I just created? 回答1: Did you try this ? This also works fine. //just after you call your insert($data) function .. use this $lastInsertId = $this->getAdapter()->lastInsertId(); 回答2: One gotcha. When calling $this->getDbTable()->insert($data); you have to make sure $data include the "primary key" of your table. For example

How does one use the RDBMS in a performant way on top of Zend_Db_Table? (if at all…)

↘锁芯ラ 提交于 2019-12-01 13:14:54
There's this constant war going on in my thoughts when I work on a Zend Framework project -- good application design mandates that the number of database queries be minimized. Each query is expensive in terms of both latency and RDBMS calculation time. And Zend_Db_Table encourages you to make lots of queries -- there's no built in way to JOIN with other Zend_Db_Tables, for example. And there's no way to extract the name of the underlying table given an instance of Zend_Db_Table, which makes writing Zend_Db_Select queries in terms of Zend_Db_Table difficult. In a sense, Zend_Db_Table encourages

How does one use the RDBMS in a performant way on top of Zend_Db_Table? (if at all…)

偶尔善良 提交于 2019-12-01 11:01:21
问题 There's this constant war going on in my thoughts when I work on a Zend Framework project -- good application design mandates that the number of database queries be minimized. Each query is expensive in terms of both latency and RDBMS calculation time. And Zend_Db_Table encourages you to make lots of queries -- there's no built in way to JOIN with other Zend_Db_Tables, for example. And there's no way to extract the name of the underlying table given an instance of Zend_Db_Table, which makes

zend relationships with select

萝らか妹 提交于 2019-11-30 23:37:13
I am new to zend. I have been asked to redevelop a website that was once written in plain PHP and put it into the zend framework. I am having a lot of trouble with database relationships, I cant seem to get my head round defining and querying relationships. I would like to find a Category. From that Category I would like to be able to find all the CategoryInfo associated with it, and be able to query/sort/limit that dataset. Here are my models. Categorys.php <?php class Default_Model_Categorys extends Zend_Db_Table_Abstract { protected $_name = 'Categorys'; protected $_primary = 'id';

Zend Framework Db Select Join table help

大城市里の小女人 提交于 2019-11-30 21:34:24
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); return $resultRows; Anyone know what I could be doing wrong? I want to get all the columns in 'games' to

Zend Framework Complex Where Statement

谁说胖子不能爱 提交于 2019-11-30 19:36:25
问题 This method is published as offical example ->where("price < $minimumPrice OR price > $maximumPrice") is such method safe? want to write it as ->where("price < ? OR price > ?", $minimumPrice, $maximumPrice) are there any poissibility? and I can't split it into 2 where statements because plan to write query ->where("1 OR 2") ->where("3 OR 4") 回答1: If I have complex WHERE clauses I use the db adapters' ->quoteInto() method like: $where = '(' . $dbAdapter->quoteInto('price1 < ?', $price1) . ' OR