Skip to content
Snippets Groups Projects
Commit 87bafef8 authored by Jared Hancock's avatar Jared Hancock
Browse files

mysqli: Allow for persistent database spec

Use `p:` in the database hostname specification, so `p:localhost` for
instance. This will help with SSL and remote database users.

References:
http://www.php.net/manual/en/mysqli.persistconns.php
parent 62049df7
No related branches found
No related tags found
No related merge requests found
...@@ -40,6 +40,9 @@ function db_connect($host, $user, $passwd, $options = array()) { ...@@ -40,6 +40,9 @@ function db_connect($host, $user, $passwd, $options = array()) {
$port = ini_get("mysqli.default_port"); $port = ini_get("mysqli.default_port");
$socket = ini_get("mysqli.default_socket"); $socket = ini_get("mysqli.default_socket");
$persistent = stripos($host, 'p:') === 0;
if ($persistent)
$host = substr($host, 2);
if (strpos($host, ':') !== false) { if (strpos($host, ':') !== false) {
list($host, $portspec) = explode(':', $host); list($host, $portspec) = explode(':', $host);
// PHP may not honor the port number if connecting to 'localhost' // PHP may not honor the port number if connecting to 'localhost'
...@@ -54,6 +57,9 @@ function db_connect($host, $user, $passwd, $options = array()) { ...@@ -54,6 +57,9 @@ function db_connect($host, $user, $passwd, $options = array()) {
} }
} }
if ($persistent)
$host = 'p:' . $host;
// Connect // Connect
$start = microtime(true); $start = microtime(true);
if (!@$__db->real_connect($host, $user, $passwd, null, $port, $socket)) if (!@$__db->real_connect($host, $user, $passwd, null, $port, $socket))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment