zend-db-table

Zend Framework DbTable insert() inserting records twice

被刻印的时光 ゝ 提交于 2019-12-24 07:01:14
问题 I have a controller action as follows public function reportcommentAction() { $comment_id = $this->getRequest()->comment_id; $blockedCommentTable = new Application_Model_DbTable_BlockedComments(); $blockedCommentTable->blockComment($comment_id, $this->user_id); } which makes a call to the blockComment() dbTable model which looks like this class Application_Model_DbTable_BlockedComments extends Zend_Db_Table_Abstract { protected $_name = 'blocked_comments'; public function blockComment(

How Zend DB Manage Database Connections

半世苍凉 提交于 2019-12-22 06:41:02
问题 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

Zend_Db: How to get the number of rows from a table?

眉间皱痕 提交于 2019-12-21 07:31:31
问题 I want to find out how many rows are in a table. The database that I am using is a MySQL database. I already have a Db_Table class that I am using for calls like fetchAll() . But I don't need any information from the table, just the row count. How can I get a count of all the rows in the table without calling fetchAll() ? 回答1: $count = $db->fetchOne( 'SELECT COUNT(*) AS count FROM yourTable' ); 回答2: Counting rows with fetchAll considered harmful. Here's how to do it the Zend_Db_Select way:

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

Hand made queries vs findDependentRowset

我怕爱的太早我们不能终老 提交于 2019-12-20 02:56:29
问题 I have built a pretty big application with Zend and i was wondering which would be better, building query by hand (using the Zend object model) $db->select() ->form('table') ->join('table2', 'table.id = table2.table_id') or going with the findDependentRowset method (Zend doc for findDependentRowSet). I was wondering since i did a test to fetch data over multiple tables and display all the informations from a table and the findDependentRowset seemed to run slower. I might be wrong but i guess

How can disable quote join Zend db

不问归期 提交于 2019-12-13 04:01:01
问题 I've sql query select * from table1 left join (values (4),(1800),(103500)) AS "filter (id) on table1.id=filter.id By default Zend_Db_Select table quoted. For example: $result = '(values (4),(1800),(103500)) AS filter (id)'; $select->joinInner($result, "table1.id = filter.id", ''); result: SELECT * FROM "table1" INNER JOIN "(values (4),(1800),(103500)) filter (id)" ON table1.id=filter.id Me need SELECT * FROM "table1" INNER JOIN (values (4),(1800),(103500)) filter (id) ON table1.id=filter.id

Increment a column in MySQL

爱⌒轻易说出口 提交于 2019-12-12 23:31:53
问题 Is there a way in Zend to increment an integer, held in a MySQL column, by 1? Thanks edit: My current code is like: $row = $this->find($imageId)->current(); $row->votes = // THIS IS WHERE I WANT TO SAY INCREMENT $row->save(); 回答1: Might I offer the following suggestion $row->votes++; 回答2: Yes there is. Here's an example using products and incrementing a quantity field: $table = 'products'; $data = array('prd_qnty' => new Zend_Db_Expr('prd_qnty + 1')); $where[] = $db->quoteInto('pr_id = ?',

How can I join tables in Zend while using a class that inherits from Zend_Db_Table_Row_Abstract?

空扰寡人 提交于 2019-12-12 17:19:28
问题 I have a class that extends Zend_Db_Table lets call it 'Users' that uses the class 'User' (inheriting from Zend_Db_Table_Row_Abstract) as its rowClass. I need it this way because User has additional methods that I use. As far as I know it is not possible to join tables inside my Users class so I use: $query = $db->select(); $query->from(...); $query->joinInner(...); instead of $this->select(); ... But then of course the rows I get are not of the User class. So I would like to know how can I

zf2 form: populate select field with data coming from database

最后都变了- 提交于 2019-12-12 13:55:32
问题 I'm learning zf2 and I'm facing a problem involving 2 (eventually more) modules working together. Note, I've carefully read this post (and the related one) which helped me a lot. I'm going to explain a bit the problem: Using the first module (FrOption) an administrator can manage website form options. All options are stored in a db table like this: id|field_name|field_value 1|country|germany| 2|country|france| 3|gender|Male| 4|gender|Female| 5|tipo|Car| 6|tipo|Fly| ... In my module (FrItem) I

“IS NULL” in Zend_Db_Table select not working

喜欢而已 提交于 2019-12-12 08:48:36
问题 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