Skip to content
This repository was archived by the owner on Aug 23, 2019. It is now read-only.

Commit 281619b

Browse files
committed
Allow non-default port in MySQL connection
1 parent 1bd54a7 commit 281619b

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

qa-config-example.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
3030
For persistent connections, set the QA_PERSISTENT_CONN_DB at the bottom of this file; do NOT
3131
prepend the hostname with 'p:'.
32+
33+
To use a non-default port, add the following line to the list of defines, with the appropriate port number:
34+
define('QA_MYSQL_PORT', '3306');
3235
*/
3336

3437
define('QA_MYSQL_HOSTNAME', '127.0.0.1');

qa-include/qa-base.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ function qa_undo_wordpress_quoting($param, $isget)
262262
define('QA_FINAL_EXTERNAL_USERS', QA_EXTERNAL_USERS);
263263
}
264264

265+
if (defined('QA_MYSQL_PORT')) {
266+
define('QA_FINAL_MYSQL_PORT', QA_MYSQL_PORT);
267+
}
268+
265269
// Possible URL schemes for Q2A and the string used for url scheme testing
266270

267271
define('QA_URL_FORMAT_INDEX', 0); // http://...../index.php/123/why-is-the-sky-blue

qa-include/qa-db.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ function qa_db_connect($failhandler=null)
6060
return;
6161

6262
// in mysqli we connect and select database in constructor
63-
if (QA_PERSISTENT_CONN_DB)
64-
$db = new mysqli('p:'.QA_FINAL_MYSQL_HOSTNAME, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE);
63+
$host = QA_PERSISTENT_CONN_DB ? 'p:'.QA_FINAL_MYSQL_HOSTNAME : QA_FINAL_MYSQL_HOSTNAME;
64+
if (defined('QA_FINAL_MYSQL_PORT'))
65+
$db = new mysqli($host, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE, QA_FINAL_MYSQL_PORT);
6566
else
66-
$db = new mysqli(QA_FINAL_MYSQL_HOSTNAME, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE);
67+
$db = new mysqli($host, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE);
6768

6869
// must use procedural `mysqli_connect_error` here prior to 5.2.9
6970
$conn_error = mysqli_connect_error();

0 commit comments

Comments
 (0)