zend-db

Zend_Validate_Db_RecordExists against 2 fields

那年仲夏 提交于 2019-12-22 05:41:10
问题 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 回答1: To do

last insert id with zend db table abstract

巧了我就是萌 提交于 2019-12-22 01:40:46
问题 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 回答1: try $id = $tablemodel->insert($data); echo $id; 回答2: $last_id = $tablemodel->getAdapter()->lastInsertId(); 回答3: you can use lastInsertId Method echo 'last inserted id: ' . $db->lastInsertId(); 回答4: $insert_id = $this->db->getLastId() worked for me 回答5: user after insert query $this-

Zend DB and encoding

会有一股神秘感。 提交于 2019-12-21 18:12:03
问题 I have just encountered something rather strange, I use the Zend Framework 1.10 with the Zend_Db_Table module to read some data from a databse. The database itself, the table and the fields in question all have their collation set to "utf8_general_ci" and all special chars appear correctly formatted in the DB when checked with phpMyAdmin. Also, saving with Zend_Db_Table works just fine, yet when I read the data and just echo it to my browser it is returned as ISO-8859-1, not as UTF8. I

ZF2 - BjyAuthorize - How to Get Rules and Guards from a Database

本秂侑毒 提交于 2019-12-21 02:34:15
问题 I'm using BjyAuthorize with Zend Framework2 to implement authorization and was able to successfully integrate roles from database. Now I want to get my Rules and Guards also from data base tables. How can I do this? 回答1: The easiest method and "the trick" here is really to: Get your rules and guards into the same array format as it is shown in example configuration. So after reading records from the database, in whatever format your raw database data is, process it to match the same guard

How to Use Multiple Conditions In An Update Statement With Zend_Db And QuoteInto

本秂侑毒 提交于 2019-12-20 17:37:48
问题 Using Zend Framework, is there a way to pass multiple conditions to an update statement using the quoteInto method? I've found some references to this problem but I'm looking for a supported way without having to extend Zend_Db or without concatenation. $db = $this->getAdapter(); $data = array('profile_value' => $form['profile_value']); $where = $db->quoteInto('user_id = ?', $form['id']) . $db->quoteInto(' AND profile_key = ?', $key); $this->update($data, $where); References http://blog

How to create WHERE IN clause with Zend_Db_Select

久未见 提交于 2019-12-20 09:09:16
问题 So I am trying to accomplish something like this: SELECT * FROM table WHERE status_id IN (1,3,4); using Zend_Db_Select... can't find how to do it :( Is it at all possible? 回答1: you can also use it like this: $data = array(1,3,4); $select->where('status_id IN(?)', $data); you dont need to implode array, and it's safer 回答2: The first answer probably works in ZF1 but it doesn't work in Zend Framework 2: $data = array(1,3,4); $select->where('status_id IN(?)', $data); In case the Zend Framework2 I

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

How To Use Zend Framework To Export To CSV Using mySQL's INTO OUTFILE Functionality

帅比萌擦擦* 提交于 2019-12-20 02:59:17
问题 I am looking to export a large amount of data into a CSV file for user download using Zend Framework. Is there any way to use Zend_Db's functionaity and use the "INTO OUTFILE" syntax to output the file as a csv? Basically I want to be able to adapt my Zend_Db models to export to a csv file instead of returning a PHP array. An example of the mysql syntax I want to use would be: SELECT a,b,a+b INTO OUTFILE '/tmp/result.text' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED

How to use union in zend db

心已入冬 提交于 2019-12-19 07:39:13
问题 In sql i am using union i don't know how to write it in zend db. select m.*, 0 as is_shared from test m where user_id = $userId union select m.*,1 as is_shared from test m join test_shares ms where m.test_id = ms.test_id and ms.email_address = $email and m.url is not null; Please help me out.... I tried like this but no use $cols1 = array('test.*,0 as is_shared'); $select1 = $db->select () ->from ( 'test', $cols1 ) ->where ( 'user_id = ?', $userId); $cols2 = array('test_shares.*', '1 as is

Zend DB Framework examine query for an update

允我心安 提交于 2019-12-18 10:14:37
问题 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."'"); ?? 回答1: Use Zend_Db_Profiler to capture and report SQL statements: $db->getProfiler()-