public function bandwidthDataConnect($host, $user, $pass, $database, $website)
{
+ // Initialize MySQLi
+ $this->bwdb = mysqli_init();
+
+ // Set a short timeout
+ $this->bwdb->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
+
// Connect to MySQL
- $this->bwdb = mysqli_connect($host, $user, $pass, $database);
+ $this->bwdb->real_connect($host, $user, $pass, $database);
- if (!$this->bwdb) {
- $this->bwdb = false;
+ // If there was an error connecting
+ if ($this->bwdb->connect_errno) {
return mysqli_connect_error();
}
$this->bandwidthGetWebsiteID($website);
if (!$this->siteId) {
- $this->bwdb = false;
return "Website Name not found: ".$website;
}
* @access public
*/
public $dbError = '';
+ /**
+ * Stats Results
+ *
+ * @var $haveStats
+ * @access public
+ */
+ public $stats = false;
/**
* Server Stats Database Connection Enabled
*
}
// Connect to server stats database
- $this->bandwidthDataConnect(
+ $this->dbError = $this->bandwidthDataConnect(
$dbData['db_host'],
$dbData['db_user'],
$dbData['db_pass'],
$stats = false;
// Check for good database connection
- if ($this->bwdb != false) {
+ if ($this->dbError == '') {
// Get current summary stats
- $stats = $this->bandwidthGetStats();
+ $this->stats = $this->bandwidthGetStats();
// Build summary info
$thisDate = date('m/d/Y');
// Compile template data
$templateData = array(
+ 'dbError' => $this->dbError,
'serverStatsEnabled' => $this->enabled,
- 'serverStats' => $stats,
+ 'serverStats' => $this->stats,
'thisDate' => $thisDate,
'thisDateTime' => $thisDateTime,
'thisMonth' => $thisMonth,
});
</script>
{else}
-<h3><span class="glm-error">NOTE:</span> Unable to connect to server stats database!</h3>
-Check Server Stats Management setting<br>
+<p>
+ <span class="glm-error">NOTE:</span> Unable to connect to server Bandwidth Statistics database!<br>{$dbError}
+</p>
{/if}
{/if}
\ No newline at end of file