zend-db-table

How Zend DB Manage Database Connections

☆樱花仙子☆ 提交于 2019-12-05 10:54:15
I am using Zend Framework for my PHP developments and here is a small function I used to execute a query. This is not about an error. The code and everything works fine. But I want to know some concept behind this. /** * Get dataset by executing sql statement * * @param string $sql - SQL Statement to be executed * * @return bool */ public function executeQuery($sql) { $this->sqlStatement = $sql; if ($this->isDebug) { echo $sql; exit; } $objSQL = $this->objDB->getAdapter()->prepare($sql); try { return $objSQL->execute(); } catch(Exception $error) { $this->logMessage($error->getMessage() . " SQL

MasterSlaveFeature How-To

早过忘川 提交于 2019-12-05 02:06:10
问题 I currently have my Db Models using AbstractTableGateway and all my select/insert/update/delete queries are working just fine. But now I would like to add the MasterSlaveFeature and I'm a bit confused on how to do this. The documentation doesn't exactly give a good example: http://zf2.readthedocs.org/en/latest/modules/zend.db.table-gateway.html#tablegateway-features I currently have this setup: namespace Login\Model; use Zend\Db\TableGateway\Feature\MasterSlaveFeature; use Zend\Db

Zend_Db subquery

烈酒焚心 提交于 2019-12-04 07:43:45
I've been trying to construct a sql query with ZendFW, but I cant seem to get it to function like I want to (or function at all). This is the query that works that I'm trying to build with zend_db select() SELECT tc.trip_title, td.ID, td.trip_id, (SELECT count(*) FROM 'trips_invites' ti WHERE ti.destination_id=td.ID AND ti.accepted ='NR') AS "pending_invites" FROM `trips_current` AS `tc`, `trips_data` AS `td` WHERE (tc.ID=td.trip_id) AND (tc.creator_id = '1') ORDER BY `trip_id` ASC What I can't figure out is how to properly get that subquery in there, and nothing I try seems to work. Any help

“IS NULL” in Zend_Db_Table select not working

最后都变了- 提交于 2019-12-04 06:40:35
I'm trying to do a join on 2 tables in Zend, using the DbTable / model / mapper structure. If, in my mapper, I do this: $select = $this->getDbTable()->select(Zend_Db_Table::SELECT_WITH_FROM_PART) ->setIntegrityCheck(false) ->join('images', 'images.oldFilename = availablePictures.filename') ->where('images.ref IS NOT NULL'); $resultSet = $this->getDbTable()->fetchAll( $select ); it works like a charm, but if I try the same thing with IS NULL instead of NOT NULL, I get nothing where I should get a result set of several rows, just like when I try it directly in MySQL with SELECT * FROM (

MasterSlaveFeature How-To

半腔热情 提交于 2019-12-03 16:27:24
I currently have my Db Models using AbstractTableGateway and all my select/insert/update/delete queries are working just fine. But now I would like to add the MasterSlaveFeature and I'm a bit confused on how to do this. The documentation doesn't exactly give a good example: http://zf2.readthedocs.org/en/latest/modules/zend.db.table-gateway.html#tablegateway-features I currently have this setup: namespace Login\Model; use Zend\Db\TableGateway\Feature\MasterSlaveFeature; use Zend\Db\TableGateway\Feature\FeatureSet; use Zend\Db\TableGateway\AbstractTableGateway; use Zend\Db\Sql\Select; use Zend

Zend Framework: Proper way to interact with database?

雨燕双飞 提交于 2019-12-03 06:17:05
问题 I'm fairly new to the Zend Framework and MVC and I'm a bit confused by Zend_DB and the proper way to interact with the database. I'm using the PDO MySQL adapter and have created some classes to extend the abstract classes: class Users extends Zend_Db_Table_Abstract { protected $_name = 'users'; protected $_primary = 'user_id'; protected $_rowClass = 'User'; public function getUserbyID($id) { /* code */ } // More code here } class User extends Zend_Db_Table_Row_Abstract { // Code here } class

Translating a query to use Zend_Db_Select

拜拜、爱过 提交于 2019-12-03 03:20:19
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' => 'memberships'), array('b.id', 'b.title', 'b.description')) ->join(array('b' => 'blogs'), 'b.id = m.blog_id') -

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(

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 to do a joined query in the ZF tables interface?

我怕爱的太早我们不能终老 提交于 2019-12-01 13:18:07
I have the db and my tables look like this: alt text http://img15.imageshack.us/img15/2568/stackdijag.png What I want to do is to get all models where manufacturers name column starts with A. Which means that that simple part of query should be like $manufacturers->fetchAll("name LIKE '$letter%'"); I am trying to accomplish this with ZF relations but it ain't going, so any kind of help is welcome... $models = new Models(); $select = $models->select(Zend_Db_Table::SELECT_WITH_FROM_PART); $select->setIntegrityCheck(false) ->join(array("a"=>"manufacturers"), 'models.manufacturer_id = a.id', array