Skip to content

Commit

Permalink
Allow non-default port in MySQL connection
Browse files Browse the repository at this point in the history
  • Loading branch information
svivian committed Nov 14, 2015
1 parent 1bd54a7 commit 281619b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions qa-config-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions qa-include/qa-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions qa-include/qa-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 281619b

Please sign in to comment.