when i try connecting to my sql server database from my zf2 application as shown below,
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'sqlsrv:dbname=album;hostname=192.168.0.20',
'username' => 'user',
'password' => 'pass',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
I get this error,
File:
/usr/local/zend/apache2/htdocs/zf2-tutorial/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Connection.php:289
Message:
Connect Error: could not find driver
Am i missing something here? Or rather this does not work at all on the linux oriented machines ?
Try taking out this line:
"// PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''"
. Your connection say you are trying to connect toMSSQL
and notMySQL
.The problem is that you don't have the necessary driver installed. I had the same problem with postgres, and this solved it for me:
However, I am not 100% sure what driver must be installed to make Sql Server work. I did read that it's no longer supported. See this: PHP PDO to MS SQL Server on Ubuntu Server. In a nutshell, your best bet is to rather use:
and then connection string:
From what I gather, that should connect you to a Sql Server database, but again, I can't gaurantee this because I don't have a setup to test it with. Hope that helps...
I always prep it like this without trouble, using dist files to set the right connection params as you work through deployment:
local config file
Then in my Module.php, I define such a factory (in the getServiceConfig array):
Hope this helps. If this doesn't work, something else is going on.. let me know, I can help.
Cheers. Alex
I hope this helps you some... I'm currently following along to the Zend Framework 2 skeleton application guide. My database parameters needed to be passed in the following way: