Skip to content

Commit 83aac06

Browse files
committed
Minor refactoring (qa-db.php)
1 parent 6da7720 commit 83aac06

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

qa-include/qa-db.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,25 @@ function qa_db_connect($failhandler=null)
5959
if ($qa_db_connection instanceof mysqli)
6060
return;
6161

62-
// in mysqli we connect and select database in constructor
63-
$host = QA_PERSISTENT_CONN_DB ? 'p:'.QA_FINAL_MYSQL_HOSTNAME : QA_FINAL_MYSQL_HOSTNAME;
62+
$host = QA_FINAL_MYSQL_HOSTNAME;
6463
$port = null;
6564

6665
if (defined('QA_FINAL_WORDPRESS_INTEGRATE_PATH')) {
67-
$host_and_port = preg_split('/:/', $host);
68-
69-
if (count($host_and_port) == 2) {
70-
$host = QA_PERSISTENT_CONN_DB ? 'p:' . $host_and_port[0] : $host_and_port[0];
66+
// Wordpress allows setting port inside DB_HOST constant, like 127.0.0.1:3306
67+
$host_and_port = explode(':', $host);
68+
if (count($host_and_port) >= 2) {
69+
$host = $host_and_port[0];
7170
$port = $host_and_port[1];
7271
}
7372
} elseif (defined('QA_FINAL_MYSQL_PORT')) {
7473
$port = QA_FINAL_MYSQL_PORT;
7574
}
7675

77-
if (!is_null($port))
76+
if (QA_PERSISTENT_CONN_DB)
77+
$host = 'p:'.$host;
78+
79+
// in mysqli we connect and select database in constructor
80+
if ($port !== null)
7881
$db = new mysqli($host, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE, $port);
7982
else
8083
$db = new mysqli($host, QA_FINAL_MYSQL_USERNAME, QA_FINAL_MYSQL_PASSWORD, QA_FINAL_MYSQL_DATABASE);

0 commit comments

Comments
 (0)