Sunday, 15 January 2012

sql server - MSSQL Access From Zend2 via Linux -



sql server - MSSQL Access From Zend2 via Linux -

i'm upgrading application presently runs on zendframework1(zf1) zendframework2(zf2). i'm having problem getting db results homecoming zf2 connection.

in zf1 test works perfectly:

$db = zend_db::factory('pdo_mssql', array( 'host' => 'servernamefromfreetdsconfig', 'charset' => 'utf-8', 'username' => 'myusername', 'password' => 'mypassword', 'dbname' => 'database_name', 'pdotype' => 'dblib' )); $stmt = $db->prepare("select * products"); $stmt->execute(); $result = $stmt->fetchall(); $stmt->closecursor();

however, i've been trying in zf2 i'm not getting anywhere. in config\autoload\global.php have:

return array( 'db' => array( 'host' => 'servernamefromfreetdsconfig', 'charset' => 'utf-8', 'dbname' => 'database_name', 'username' => 'myusername', 'password' => 'mypassword', 'driver' => 'pdo', 'pdodriver' => 'dblib', ), );

and in module.php file:

public function onbootstrap(mvcevent $e) { $eventmanager = $e->getapplication()->geteventmanager(); $moduleroutelistener = new moduleroutelistener(); $moduleroutelistener->attach($eventmanager); $config = $e->getapplication()->getservicemanager()->get('configuration'); $dbadapter = new adapter($config['db'], new sqlserver()); globaladapterfeature::setstaticadapter($dbadapter); }

then in model\products.php

class products extends abstracttablegateway { protected $table; protected $featureset; public function __construct($table = 'products') { $this->table = $table; $this->featureset = new featureset(); $this->featureset->addfeature(new globaladapterfeature()); $this->initialize(); } //test connection. public function getproducts() { $result = $this->getadapter()->query("select * products", adapter::query_mode_execute); die(var_dump($result)); } }

it looks connecting because "var_dump" above returns ["fieldcount":protected]=> int(7) right (there 7 columns in table). however, not returning results. might need work in zf2? need somehow extend zend\db\adapter\adapter using code zf1 zend_db_adapter_pdo_mssql.php file? or there simple solution i'm missing?

thanks insight.

i think dont need mention user name , password

resources.db.adapter = "sqlsrv" resources.db.host = "localhost\sqlexpress" resources.db.dbname = "databasename" resources.db.isdefaulttableadapter = true resources.db.driver_options.returndatesasstrings = true

sql-server linux zend-framework2

No comments:

Post a Comment