For my website i use a second database which needs a connection using a socket. This will not work with Drupal without hacking core since the database.mysqli.inc does not supply a socket parameter to mysql
How to reproduce:
- add a second database to your settings.php (mind the escaping of the slashes!) this db does not use a user nor password!
$db_url['default'] = 'mysqli://xiffy_nl:j4bb3rw4ky@localhost/xiffy_nl';
$db_url['trackstat'] = 'mysqli://localhost%3A%2Fvar%2Flib%2Fsqueezecenter%2Fcache%2Fsqueezecenter-mysql.sock/slimserver';
somewhere in your code make a call to db_connect('trackstat') which will render a 503 error.
How to patch
line 76 in database.mysqli.inc is crucial and plain wrong. It provides a hard-coded NULL where the socket should have been.
@mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], NULL, MYSQLI_CLIENT_FOUND_ROWS);
To get the socket from the url provided from settings.php we need a bit more code. Lines 71-76 could be replced by this working code:
if (strpos($url['host'], ':') > 0) {
$f = explode(':', $url['host']);
$url['host'] = $f[0];
$sock = $f[1];
} else $sock = NULL;
$url['path'] = urldecode($url['path']);
if (!isset($url['port'])) {
$url['port'] = NULL;
}
$connection = mysqli_init();
@mysqli_real_connect($connection, $url['host'], $url['user'], $url['pass'], substr($url['path'], 1), $url['port'], $sock, MYSQLI_CLIENT_FOUND_ROWS);
cheers xiffy
Comments
Comment #1
xiffy commentedNo one?
Strange.
Comment #2
xiffy commentedUnpatched in 6.14
Comment #3
gpk commented>No one?
Perhaps no one else has this requirement.
Bugs get fixed in 7.x first, so changing version.
Also if you can create a patch in the correct format and attach it here then there is a bigger chance someone else will have a look. This might be regarded as a feature request though in which case it is unlikely to make it into 6.x core.
Comment #4
Crell commentedI'm pretty sure this would be a new feature request for D6, so it wouldn't go in.
For D7, we're not using mysqli anymore. We're using PDO-MySQL for everything. So the code in question here is completely different.
We don't yet have socket support in D7, either, but there's already an open patch for it that could use some more love: #561400: No way to specify MySQL socket with DBTNG
So marking this as a duplicate.