Note that there are some explanatory texts on larger screens.

plurals
  1. POMSSQL Access From Zend2 via Linux
    primarykey
    data
    text
    <p>I'm upgrading an application that presently runs on ZendFramework1(ZF1) to ZendFramework2(ZF2). I'm having trouble getting DB results to return from the ZF2 connection.</p> <p>In ZF1 this test works perfectly:</p> <pre><code>$db = Zend_Db::factory('Pdo_Mssql', array( 'host' =&gt; 'ServerNameFromFreeTdsConfig', 'charset' =&gt; 'UTF-8', 'username' =&gt; 'myUsername', 'password' =&gt; 'myPassword', 'dbname' =&gt; 'database_name', 'pdoType' =&gt; 'dblib' )); $stmt = $db-&gt;prepare("select * from Products"); $stmt-&gt;execute(); $result = $stmt-&gt;fetchAll(); $stmt-&gt;closeCursor(); </code></pre> <p>However, I've been trying this in ZF2 but I'm not really getting anywhere. In my config\autoload\global.php I have:</p> <pre><code>return array( 'db' =&gt; array( 'host' =&gt; 'ServerNameFromFreeTdsConfig', 'charset' =&gt; 'UTF-8', 'dbname' =&gt; 'database_name', 'username' =&gt; 'myUsername', 'password' =&gt; 'myPassword', 'driver' =&gt; 'pdo', 'pdodriver' =&gt; 'dblib', ), ); </code></pre> <p>And in the Module.php file:</p> <pre><code>public function onBootstrap(MvcEvent $e) { $eventManager = $e-&gt;getApplication()-&gt;getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener-&gt;attach($eventManager); $config = $e-&gt;getApplication()-&gt;getServiceManager()-&gt;get('Configuration'); $dbAdapter = new Adapter($config['db'], new SqlServer()); GlobalAdapterFeature::setStaticAdapter($dbAdapter); } </code></pre> <p>Then in the Model\Products.php</p> <pre><code>class Products extends AbstractTableGateway { protected $table; protected $featureSet; public function __construct($table = 'Products') { $this-&gt;table = $table; $this-&gt;featureSet = new FeatureSet(); $this-&gt;featureSet-&gt;addFeature(new GlobalAdapterFeature()); $this-&gt;initialize(); } //Test the connection. public function getProducts() { $result = $this-&gt;getAdapter()-&gt;query("select * from Products", Adapter::QUERY_MODE_EXECUTE); die(var_dump($result)); } } </code></pre> <p>It looks like it is connecting because the "var_dump" above returns a ["fieldCount":protected]=> int(7) which is correct (there are 7 columns in that table). However, it is not returning any results. What might I need to do to get this to work in ZF2? Do I need to somehow extend Zend\Db\Adapter\Adapter using code from the ZF1 Zend_Db_Adapter_Pdo_Mssql.php file? Or is there some simple solution I'm missing?</p> <p>Thanks for any insight.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload