Zend Framework 1.10.3 and PDO_MSSQL

Hi,

I try to connect from the ZendFramework 1.10.3 via php_pdo_sqlsrv_52_nts.dll without success.

phpinfo shows me:

PDO section:

PDO drivers   / sqlsrv

pdo_sqlsrv section:

pdo_sqlsrv support  / enabled

 

I try to conect using the Adapter Factory Method with a  Zend_Config Objekt.

Config.ini:

[general]
db.adapter = PDO_Mssql
db.params.host = "localhost"
db.params.username = WEBUser
db.params.password = WEBUser
db.params.dbname = ZFiA_Places

Bootstrap:

$db = Zend_DB::factory($config->db);

 

I always get this Errors:

Error: The mssql driver is not currently installed
#0 C:\PHP\includes\Zend\Db\Adapter\Pdo\Mssql.php(137): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 C:\PHP\includes\Zend\Db\Adapter\Abstract.php(448): Zend_Db_Adapter_Pdo_Mssql->_connect()
#2 C:\PHP\includes\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('exec sp_columns...', Array)
#3 C:\PHP\includes\Zend\Db\Adapter\Pdo\Mssql.php(237): Zend_Db_Adapter_Pdo_Abstract->query('exec sp_columns...')
#4 C:\PHP\includes\Zend\Db\Table\Abstract.php(823): Zend_Db_Adapter_Pdo_Mssql->describeTable('places', NULL)
#5 C:\PHP\includes\Zend\Db\Table\Abstract.php(862): Zend_Db_Table_Abstract->_setupMetadata()
#6 C:\PHP\includes\Zend\Db\Table\Abstract.php(969): Zend_Db_Table_Abstract->_setupPrimaryKey()
#7 C:\PHP\includes\Zend\Db\Table\Select.php(100): Zend_Db_Table_Abstract->info()
#8 C:\PHP\includes\Zend\Db\Table\Select.php(78): Zend_Db_Table_Select->setTable(Object(Places))
#9 C:\PHP\includes\Zend\Db\Table\Abstract.php(1005): Zend_Db_Table_Select->__construct(Object(Places))
#10 C:\PHP\includes\Zend\Db\Table\Abstract.php(1303): Zend_Db_Table_Abstract->select()

I thinkthe Problem is that the PDO_Mssql Driver is named in phpinfo() with sqlsrv and not Mssql.

Have anyone an Idea whats wrong???

How can I get this thing running.

 

The "normal" connection over the PDO driver like this is working.

 

   $serverName = "(local)";
   $database = "AdventureWorks";

   // Get UID and PWD from application-specific files.
   $uid = 'WEBUser';
    $pwd = 'WEBUser';

   try {
      $conn = new PDO( "sqlsrv:$serverName", $uid, $pwd, array( 'Database' => $database ) );
      $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
   }

   catch( PDOException $e ) {
      die( "Error connecting to SQL Server" );
   }

   echo "Connected to SQL Server\n";

   $query = 'select * from Person.ContactType';
   $stmt = $conn->query( $query );
   while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
      print_r( $row );
   }

   // Free statement and connection resources.
   $stmt = null;
   $conn = null;

 

April 23rd, 2010 11:59am

I don't know anything about PDO, but shouldn't your configuration choose the pdo sqlsrv extension, and not this? :

db.adapter = PDO_Mssql

Your error report tells you the same thing - MSSQL and SQLSRV are not the same thing.

try: PDO_sqlsrv instead.

Free Windows Admin Tool Kit Click here and download it now
April 23rd, 2010 12:51pm

Post all of the extension= lines of your php.ini.

You need something like

extension=php_sqlsrv_53_ts_vc6.dll
extension=php_pdo_sqlsrv_53_ts_vc6.dll

phpinfo() should have:

PDO support   enabled
PDO drivers   sqlsrv

 

April 23rd, 2010 1:32pm

if I use PDO_sqlsrv I get the message:

 

PHP Warning: include_once(Zend\Db\Adapter\Pdo\Sqlsrv.php) [<a href='function.include-once'>function.include-once</a>]: failed to open stream: No such file or directory in C:\PHP\includes\Zend\Loader.php on line 146

 

so it means there is no adapter File in Zend Framework....

 

 

 

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2010 6:48am

yes that's installed and works.

I have tested it with the microsoft example. I can connect the Adwnture Works Db and can read datas.

 

April 27th, 2010 6:50am

Eric

I think MMR_Megalith already had the driver loaded, because the original post states:

"PDO section:

PDO drivers   / sqlsrv

pdo_sqlsrv section:

pdo_sqlsrv support  / enabled"

 

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2010 3:25pm

Please confirm that the version of Zend Framework you are using has support for the PDO_SQLSRV driver (not just the PDO_MSSQL driver).

June 17th, 2010 7:43pm

Hi MMR_Megalith,

 

How did you resolve this.

I am getting the following error:

PHP Warning: include_once(Zend\Db\Adapter\Pdo\Sqlsrv.php): failed to open stream: No such file or directory in C:\Inetpub\wwwroot\app1\library\Zend\Loader.php on line 146 PHP Warning

 

In phpinfo I can only see the mysql pdo driver.

Any help is appreciated.

Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 4:31pm

Issue: You properly installed the new SQLSRV drivers, but are still referencing the old MSSQL drivers.

Solution: Replace MSSQL with SQLSRV.

 

For those who are having a "failed to open stream" error:

Issue: Since Pdo_Sqlsrv is new as of a few months ago, Zend Framework lacks a Pdo\Sqlsrv.php class to make use of the Pdo_Sqlsrv driver.

Solutions:

-Use the normal Sqlsrv driver and class

-Copy/paste the Pdo\Mssql.php and modify it to work with Pdo_Sqlsrv

-Try this class (I can vouch for the author being very helpful and knowledgable, but I have not tested his code): https://github.com/akrabat/Akrabat/blob/master/zf1/Akrabat/Db/Adapter/Pdo/Sqlsrv.php

November 19th, 2010 7:54pm

what is the meaning of normal Sqlsrv driver and class? is it means the pure PDO_SQLSRV develop by php, rather than zend???

modify Pdo_mssql to Pdo_Sqlsrv is not the fianl solution yet, it still have many errors in my case finally I combine Akrabat to Pdo_mssql.php, the different is copy the following content to  _dsn
if(isset($dsn['dbname'])) {
            $dsn['Database'] = $dsn['dbname'];
            unset($dsn['dbname']);
        }
        if(isset($dsn['host'])) {
            if($dsn['host'] == '127.0.0.1') {
                $dsn['host'] = '(local)';
            }
            $dsn['Server'] = $dsn['host'];
            unset($dsn['host']);
        }
        unset($dsn['charset']);
        unset($dsn['params']);       

and I want to remind everyone Akrabat is not pefect too, it has bugs in limit() method but PDO_mssql has been solved.

Free Windows Admin Tool Kit Click here and download it now
August 5th, 2015 12:29am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics