ZF-4773: Pass socket parameter into Mysqli constructor

Description

The Pdo_Mysql adapter accepts a "unix_socket" parameter in its options array, but the plain Mysqli Adapter doesn't. Case ZF-1914 suggests that this isn't needed because you can set it in php.ini, but there are still some cases where it's nice to pass it in on the fly. In either case, this should be simple to add.

After line 299 in library/Zend/Db/Adapter/Mysqli.php:


        if (isset($this->_config['unix_socket'])) {
            $socket = $this->_config['unix_socket'];
        } else {
            $socket = null;
        }

And then continuing and replacing starting at existing line 300:


        // Suppress connection warnings here.
        // Throw an exception instead.
        @$this->_connection = new mysqli(
            $this->_config['host'],
            $this->_config['username'],
            $this->_config['password'],
            $this->_config['dbname'],
            $port,
            $socket
        );

(Existing line 309 would follow... It seems to be munching the spaces on the first respective lines as well.)

I tried this on my local installation, and it seems to work both in cases where you do and don't use sockets.

Comments

Added a patch against latest trunk

can someone close this issue since it duplicates another issue which has been resolved?

See resolution in ZF-1914

Well, this issue is actually not resolved in ZF-1914, as I mentioned in the original report. ZF-1914 suggests that you should set the socket in the php.ini file, but that doesn't allow you to use different sockets on a per-connection basis. If you use PDO now, it will work, but not with mysqli. The one line added suggested in the original report would fix the issue, though; in 1.11 that line still isn't there.

Maybe resolve as "Not an issue" if you choose, but it isn't a duplicate. ZF-5053 is a duplicate of this, though.

@Brian: Ah, you're right. Apologies. Reopening & will look into writing a test case and getting this applied.

Attaching patch that also updates documentation for mysqli adapter.

I was wondering why I have still been using my own connect method. Thanks for the quick response and moving to get this issue resolved!

Fixed on trunk (25228) and release-1.12 (25229)

Thanks to Marc!