zend-db

Zend db adapter mysqli or PDO_MYSQL

◇◆丶佛笑我妖孽 提交于 2019-12-05 18:20:25
I've seen several code samples that do this in application.ini resources.db.adapter = mysqli or resources.db.adapter = PDO_MYSQL What is the real difference between the two? Does it impact my code? when should I choose one or the other? I developed a lot of the Zend_Db component for Zend Framework through the 1.0 release. It was the goal that the adapters function identically, or as close to it as could be supported by the PHP extension. The same set of unit tests can be run against both MySQL adapters, with virtually no difference. Performance-wise, there's no measurable difference. The

Zend Framework: How to find a table row by the value of a specified column?

让人想犯罪 __ 提交于 2019-12-05 16:03:47
I am implementing my model exactly like the quickstart guide . In my model I am trying to implement a findByToken() method. The current find() method accepts an $id parameter, but I want to find by the value of a different column. //excerpt from the quickstart guide public function find($id, Default_Model_Guestbook $guestbook) { $result = $this->getDbTable()->find($id); if (0 == count($result)) { return; } $row = $result->current(); $guestbook->setId($row->id) ->setEmail($row->email) ->setComment($row->comment) ->setCreated($row->created); } I tried doing something like this, but I don't think

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

[zend][db] fetchAll with multiple variables

冷暖自知 提交于 2019-12-05 10:27:10
I'm trying to use fetchAll on a query that has 2 variables. I can't figure out the syntax. I can manage with only 1 variable: $sql = "SELECT * FROM mytable WHERE field1 = ?"; $this->_db->fetchAll($sql,$value1); # that works However I'm having some issues when query has multiple variables $sql = "SELECT * FROM mytable WHERE field1 = ? AND field2 = ?"; $this->_db->fetchAll($sql,$value1,$value2); # doesn't work $this->_db->fetchAll($sql,array("field1"=>$value1,"field2"=>$value2)); # doesn't work either The reason why I want to use ? instead of placing the variables directly into the query is that

Zend_Validate_Db_RecordExists against 2 fields

自古美人都是妖i 提交于 2019-12-05 06:50:27
I usualy use Zend_Validate_Db_RecordExists to update or insert a record. This works fine with one field to check against. How to do it if you have two fields to check? $validator = new Zend_Validate_Db_RecordExists( array( 'table' => $this->_name, 'field' => 'id_sector,day_of_week' ) ); if ($validator->isValid($fields_values['id_sector'],$fields_values['day_of_week'])){ //true } I tried it with an array and comma separated list, nothing works... Any help is welcome. Regards Andrea To do this you would have to extend the Zend_Validate_Db_RecordExists class. It doesn't currently know how to

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_Select order by random, compatible in mssql / mysql

試著忘記壹切 提交于 2019-12-05 00:18:08
问题 Alright here's the situation, I have an application written in the Zend_Framework, that is compatible with both MySQL and MSSQL as the backend. Now, ZF is pretty good at solving a lot of the SQL discrepancies/differences between the two languages, but I still have yet to figure this one out. The objective is to select 1 random record from the table, which is an extremely simple statement. Here's a select statement for example: $sql = $db->select() ->from("table") ->order("rand()") ->limit(1);

last insert id with zend db table abstract

一笑奈何 提交于 2019-12-04 23:51:38
variable $tablemodel in an instance of a model which extends Zend_Db_Table_Abstract , if i do $tablemodel->insert($data) to insert data. Is there any method or property to get last insert id? regards try $id = $tablemodel->insert($data); echo $id; Art3mk4 $last_id = $tablemodel->getAdapter()->lastInsertId(); you can use lastInsertId Method echo 'last inserted id: ' . $db->lastInsertId(); $insert_id = $this->db->getLastId() worked for me user after insert query $this->dbAdapter->getDriver()->getLastGeneratedValue(); 来源: https://stackoverflow.com/questions/4842064/last-insert-id-with-zend-db

How update a database table record in Zend?

折月煮酒 提交于 2019-12-04 22:29:53
I am using select like this and it is fetching record successfully: $table = new Bugs(); $select = $table->select(); $select->where('bug_status = ?', 'NEW'); $rows = $table->fetchAll($select); But Now I want to update same record. For example in simple MySQL. UPDATE TableName Set id='2' WHERE id='1'; How to execute above query in Zend ? Thanks $data = array( 'field1' => 'value1', 'field2' => 'value2' ); $where = $table->getAdapter()->quoteInto('id = ?', $id) $table = new Table(); $table->update($data, $where); Since you're already fetching the row you want to change, it seems simplest to just

Using Zend_Db and multiple tables

本秂侑毒 提交于 2019-12-04 21:59:59
I have a normalized database that stores locations of files on the internet. A file may have multiple locations spread across different sites. I am storing the urls in two parts (Site.UrlStart, FileLocation.UrlEnd). The UrlEnd is the part unique to that file (for the site). Simplified Db structure: http://img231.imageshack.us/img231/9134/dblayout.jpg I am using Zend_Db as my ORM (If it is that), with classes for the tables inheriting from Zend_Db_Table_Abstract. The issue is that retrieving the location data (e.g. the url) requires the use of multiple tables and as far as I can make out and I