ZF-6739: Connect to a database with trusted connection

Issue Type: Improvement Created: 2009-05-20T04:08:00.000+0000 Last Updated: 2012-11-20T21:37:56.000+0000 Status: Open Fix version(s): Reporter: Jan Olsen (janpolsen) Assignee: None Tags: - Zend_Db

Related issues: - ZF-3493



I am running with "mssql.secure_connections = On" in my "php.ini" file, so I don't have to assign a username and password whenever I make query.

This works fine with PHP native mssql_* functions and the ADOdb Framework, but sadly not with the Zend Framework. At least I haven't found out how to connect to a database without assigning a username and a password.

I have found a solution to make it possible, however it is dependant on another "patch" ( by Bart McLeod.

The changes are made to the function _dsn() which should be changed to:

<pre class="highlight">
    protected function _dsn()
        // baseline of DSN parts
        $dsn = $this->_config;

        if (isset($dsn['port'])) {
            $seperator = ':';
            if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                $seperator = ',';
            $dsn['host'] .= $seperator . $dsn['port'];

        // this driver supports multiple DSN prefixes
        // @see <a href="">…</a>
        if (isset($dsn['pdoType'])) {
            switch (strtolower($dsn['pdoType'])) {
                case 'freetds':
                case 'sybase':
                    $this->_pdoType = 'sybase';
                case 'mssql':
                    $this->_pdoType = 'mssql';
                case 'odbc':
                    $this->_pdoType = 'odbc';
                    $dsn['DATABASE']    = $dsn['dbname'];
                    $dsn['DRIVER']    = '{SQL Server}';
                    $dsn['SERVER']    = $dsn['host'];
                    if (!$dsn['username'] && !$dsn['password']) {
                        $dsn['Trusted_Connection'] = "yes";
                case 'dblib':
                    $this->_pdoType = 'dblib';

        // don't pass the username and password in the DSN

        // use all remaining parts in the DSN
        foreach ($dsn as $key => $val) {
            $dsn[$key] = "$key=$val";

        $dsn = $this->_pdoType . ':' . implode(';', $dsn);
        return $dsn;

I would've loved to not being forced to use ODBC, but couldn't couldn't figure out how to make a trusted connection with PDO_MSSQL :(.


Posted by Jan Olsen (janpolsen) on 2010-02-11T04:49:42.000+0000

Crossposted from ZF-3493 since that issue apparently got closed prematurely IMHO.

Please someone look into this and let me know if I can help in any way.

I just went through updating ZendFramework from 0.9.3 to 1.10.0 and while it should've been a simple overwrite of all the files then it took a bit longer than that.

The reason... I had to manually add the attached mssql-odbc-patch as well as the changes from ZF-6739.

I can understand that there is the right way of implementing stuff as well as the wrong way, but reading that this issue might get changed to "wont-fix" (as well as ZF-905) and the lack of response in issue ZF-6739 (which is depending on this fix) then I fear that I have to manually make changes in all future releases of Zend Framework.

This fix doesn't break any functionality and just adds an extra option/setting, so why is it, that it can't be implemented?

Do we really have to install Microsofts SQLserver driver and if so, does that then solve the problems in this issue and the related issues (text fields above 4096 bytes, trusted connection and multiple queries).

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.