Permalink
Browse files

Allow non-default port in MySQL connection

  • Loading branch information...
1 parent 1bd54a7 commit 281619b46ce236c02b2d38167650f74002118411 @svivian svivian committed Nov 14, 2015
Showing with 11 additions and 3 deletions.
  1. +3 −0 qa-config-example.php
  2. +4 −0 qa-include/qa-base.php
  3. +4 −3 qa-include/qa-db.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');
@@ -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
@@ -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();

0 comments on commit 281619b

Please sign in to comment.