From 281619b46ce236c02b2d38167650f74002118411 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 14 Nov 2015 17:25:21 +0000 Subject: [PATCH] Allow non-default port in MySQL connection --- qa-config-example.php | 3 +++ qa-include/qa-base.php | 4 ++++ qa-include/qa-db.php | 7 ++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/qa-config-example.php b/qa-config-example.php index 54cf48f1b..02a5895d9 100644 --- a/qa-config-example.php +++ b/qa-config-example.php @@ -29,6 +29,9 @@ For persistent connections, set the QA_PERSISTENT_CONN_DB at the bottom of this file; do NOT prepend the hostname with 'p:'. + + To use a non-default port, add the following line to the list of defines, with the appropriate port number: + define('QA_MYSQL_PORT', '3306'); */ define('QA_MYSQL_HOSTNAME', '127.0.0.1'); diff --git a/qa-include/qa-base.php b/qa-include/qa-base.php index d9bfd1c41..f217cbe33 100644 --- a/qa-include/qa-base.php +++ b/qa-include/qa-base.php @@ -262,6 +262,10 @@ function qa_undo_wordpress_quoting($param, $isget) define('QA_FINAL_EXTERNAL_USERS', QA_EXTERNAL_USERS); } + if (defined('QA_MYSQL_PORT')) { + define('QA_FINAL_MYSQL_PORT', QA_MYSQL_PORT); + } + // Possible URL schemes for Q2A and the string used for url scheme testing define('QA_URL_FORMAT_INDEX', 0); // http://...../index.php/123/why-is-the-sky-blue diff --git a/qa-include/qa-db.php b/qa-include/qa-db.php index 3805d97bb..e8ac57695 100644 --- a/qa-include/qa-db.php +++ b/qa-include/qa-db.php @@ -60,10 +60,11 @@ function qa_db_connect($failhandler=null) return; // in mysqli we connect and select database in constructor - if (QA_PERSISTENT_CONN_DB) - $db = new mysqli('p:'.QA_FINAL_MYSQL_HOSTNAME, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE); + $host = QA_PERSISTENT_CONN_DB ? 'p:'.QA_FINAL_MYSQL_HOSTNAME : QA_FINAL_MYSQL_HOSTNAME; + if (defined('QA_FINAL_MYSQL_PORT')) + $db = new mysqli($host, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE, QA_FINAL_MYSQL_PORT); else - $db = new mysqli(QA_FINAL_MYSQL_HOSTNAME, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE); + $db = new mysqli($host, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE); // must use procedural `mysqli_connect_error` here prior to 5.2.9 $conn_error = mysqli_connect_error();