zend-db

How to use Zend Framework 2 with MS SQL Server on *nix?

对着背影说爱祢 提交于 2019-12-07 01:53:28
What, if it exists, is the canonical way to use ZF2 with MS SQL Server on a non-Windows OS? From what I can tell from the documentation , only the Sqlsrv driver is officially supported, which only works on the Windows platform. In ZF1, we used the Pdo_Mssql adapter and specified the pdoType as dblib . I can't find any references to doing anything similar in ZF2. Apparently there was a Pdo\Mssql driver some time ago which was removed during a major refactoring , but I don't see a currently documented way of using Pdo_Dblib. According to the adapter documentation above, you can set the driver in

Zend DB Selecting constants - columns that do not exist in table

旧城冷巷雨未停 提交于 2019-12-06 19:31:31
问题 I'm trying to do this query using Zend DB select but I'm not able to do so This is the sql query select shopping_id,shopping_details,"friend" as type from shopping Notice here how I'm specifying "friend" as type and friend is not a column in the shopping table. Now how do I do this in Zend. I have tried this but it gives me an error saying "sh.friend Column does not exist" $select->from(array('sh'=>'shopping'),array('shopping_id','shopping_details','"friend" as type'); Any help will be

How update a database table record in Zend?

送分小仙女□ 提交于 2019-12-06 16:52:37
问题 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 回答1: $data = array( 'field1' => 'value1', 'field2' => 'value2' ); $where = $table->getAdapter()->quoteInto('id = ?', $id) $table = new Table(); $table-

Zend_Db_Table: Delete multiple entries

醉酒当歌 提交于 2019-12-06 10:23:45
问题 I wanted to delete some db entries and each of them has a unique ID. My current code looks so, taken from here: Zend Framework: How to delete a table row where multiple things are true? $where = array(); foreach ($IDs as $ID) { $where[] = $this->getAdapter()->quoteInto('id = ?', $ID); } $this->delete($where); This is called inside the model class extends by Zend_Db_Table_Abstract. The query looks now like that: DELETE FROM `shouts` WHERE (id = '10') AND (id = '9') AND (id = '8') That doesn't

Fatal exception in loading ini file

牧云@^-^@ 提交于 2019-12-06 09:33:24
My project folder is demo, inside which I have the folders application, library and public. Inside the application folder, I have a folder named configs, inside which I have a file 'application.ini', which contains my database parameters. So, in the bootstrap.php which is in application directory, I set my database in Zend registry in a function called _initDbAdapter : $config = new Zend_Config_Ini('/demo/application/configs/application.ini', 'development'); Zend_Registry::set('config', $config); $db = Zend_Db::factory($config, $config->resources->db->params->asArray()); Zend_register('db',

Php Zend Framework : Connecting to multiple databases one at a time

流过昼夜 提交于 2019-12-06 07:32:43
I have written a script that goes through my application ini. The problem I am having now is that when I get to the next database, its still selecting from the first database and not the new one. Is it possible to close a connection and then open a new connection while running a script. Remember this is just a script I have no bootstrap set. I just setup a autoload to that I can load my models. While looping through sections of the ini try { $db = Zend_Db::factory($section->database->type, $section->database->toArray()); Zend_Db_Table::setDefaultAdapter($db); Zend_Registry::set('db', $db); }

Handeling M-N Relationship in Zend Framework 2

最后都变了- 提交于 2019-12-06 06:21:21
问题 With beta4 and latest beta5 the DB-Feature-Implementation appears to have pretty much finished. There's a couple of tutorials out there how to handle a single Database using the TableGateway Pattern, but it appears there is none for handling M-N-Relationships. In ZF1 we had findDependantRowset() on the TableGateway which was kind of dirty, as this simply was a second Query to the databse which pretty much isn't always neccessary. In ZF2 i expected there to be a way to have good Joins mapping

how to return an array of objects in zend framework 2?

梦想的初衷 提交于 2019-12-06 05:37:10
问题 I am doing a query in zf2 and i get back a object(Zend\Db\ResultSet\HydratingResultSet) that i have to a foreach on, in order to get to the properties. I would like to get an array of objects by default. here is some code i have: factory 'address-mapper' => function ($serviceManager) { $mapper = new Mapper\Address(); $mapper->setDbAdapter($serviceManager->get('Zend\Db\Adapter\Adapter')); $mapper->setEntityPrototype(new Entity\Address); $mapper->setHydrator(new \Zend\Stdlib\Hydrator

Is there a way to get the number of records from a query with Zend-framework?

≡放荡痞女 提交于 2019-12-06 01:25:10
问题 Given my generic select below, is there a way to get the number of records returned from a query with Zend Framework? $row++ in a loop is not acceptable for my solution as I am using paging (though its not in my sample). I also DO NOT want to add another query with "Count(*)". $query = "Select * from Users where active = 1"; $stmt = $db->query($query); $noOfRows = ???; while ($row = $stmt->fetch()) { // processing } 回答1: Use fetchAll() fetchAll returns an array, so you can do something like

using Zend_Db zf2 module outside of zf2 mvc

徘徊边缘 提交于 2019-12-05 22:29:50
I'm writing a PHP application that is not based on zf2 mvc. I do want to use only the Zend_Db zf2 module. how can I configure my application to know how to find the Zend_Db releveant PHP file where required ? I have zf2 Zend_db module download with phyrus and installed at the location vendor/zf2/php . I tried adding the module to the include path with the following command: set_include_path("../vendor/zf2/php".PATH_SEPARATOR.get_include_path()); I created Model class files relevant to each table (using zend-db-model-generator) inside directory Model/ . my main app contains the following: use