From 26fc3f48199eb4abe70fdb47cace5980a90a8989 Mon Sep 17 00:00:00 2001 From: ozh Date: Fri, 23 Aug 2013 20:30:12 +0200 Subject: [PATCH] Improve support for non standard DB port --- includes/class-mysql.php | 20 +++++++++++++++++++- user/config-sample.php | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/includes/class-mysql.php b/includes/class-mysql.php index 438da89..a74aaf6 100644 --- a/includes/class-mysql.php +++ b/includes/class-mysql.php @@ -21,6 +21,15 @@ function yourls_set_DB_driver( ) { } else { $driver = ''; } + + /** + mysql_connect( "$host:$port", $user, $pass, + + new mysqli( $host, $user, $pass, $dbname, $port ) + + $dsn = sprintf( 'mysql:host=%1$s;port=%2$d', $host, $port ); + new PDO( $dsn, $user, $pass ); + /**/ // Get the new driver if ( in_array( $driver, array( 'mysql', 'mysqli', 'pdo' ) ) ) { @@ -44,7 +53,16 @@ function yourls_set_DB_driver( ) { yourls_do_action( 'set_DB_driver', $driver ); - $ydb = new $class( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST ); + $port = 3306; + $host = YOURLS_DB_HOST; + if ( false !== strpos( YOURLS_DB_HOST, ':' ) ) { + list( $host, $port ) = explode( ':', YOURLS_DB_HOST ); + if ( 'pdo' == 'driver' ) { + $host = sprintf( '%1$s;port=%2$d', $host, $port ); + } + } + + $ydb = new $class( YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, $host, $port ); $ydb->debug_log[] = "DB driver: $driver"; } diff --git a/user/config-sample.php b/user/config-sample.php index aa3541e..95b501d 100644 --- a/user/config-sample.php +++ b/user/config-sample.php @@ -16,7 +16,8 @@ /** The name of the database for YOURLS */ define( 'YOURLS_DB_NAME', 'yourls' ); -/** MySQL hostname */ +/** MySQL hostname. + ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */ define( 'YOURLS_DB_HOST', 'localhost' ); /** MySQL tables prefix */ -- 2.45.0