Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Created February 21, 2014 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoheijnen/c4284c361ac4031748d9 to your computer and use it in GitHub Desktop.
Save markoheijnen/c4284c361ac4031748d9 to your computer and use it in GitHub Desktop.
mysql_connect for duplicator
static public function mysql_connect( $host, $username, $password, $dbname = '', $port = null ) {
if ( ! $port ) {
$post = ini_get("mysqli.default_port");
}
if ( 'sock' === substr( $host, -4 ) ) {
$url_parts = parse_url( $host );
$dbh = @mysqli_connect( 'localhost', $username, $password, $dbname, null, $url_parts['path'] );
}
else {
$dbh = @mysqli_connect( $host, $username, $password, $dbname, $port );
}
return $dbh;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment