From: Chuck Scott Date: Wed, 22 Feb 2017 19:37:47 +0000 (-0500) Subject: New release with enhanced connection error handling. X-Git-Tag: v1.1.0^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=15c58f2e84ff95ef73fe17eb187ea8b95cb6216b;p=WP-Plugins%2Fglm-serverstats.git New release with enhanced connection error handling. --- diff --git a/classes/serverBandwidthSupport.php b/classes/serverBandwidthSupport.php index 560c55b..4bcfee4 100644 --- a/classes/serverBandwidthSupport.php +++ b/classes/serverBandwidthSupport.php @@ -62,11 +62,17 @@ class glmServerStatsBandwidthSupport 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(); } @@ -74,7 +80,6 @@ class glmServerStatsBandwidthSupport $this->bandwidthGetWebsiteID($website); if (!$this->siteId) { - $this->bwdb = false; return "Website Name not found: ".$website; } diff --git a/index.php b/index.php index 34363a9..3431ce7 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM ServerStats - Stand Alone * Plugin URI: http://www.gaslightmedia.com/ * Description: Gaslight Media Server Stats Display. - * Version: 1.0.10 + * Version: 1.1.0 * Author: Gaslight Media * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,10 +19,10 @@ * @package glmServerStats * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.0.10 + * @version 1.1.0 */ -define('GLM_SERVERSTATS_PLUGIN_VERSION', '1.0.10'); +define('GLM_SERVERSTATS_PLUGIN_VERSION', '1.1.0'); // Check that we're being called by WordPress. if (!defined('ABSPATH')) { diff --git a/models/adminServerStats.php b/models/adminServerStats.php index 4aa71e4..1c69557 100644 --- a/models/adminServerStats.php +++ b/models/adminServerStats.php @@ -50,6 +50,7 @@ class adminServerStats extends glmServerStatsBandwidthSupport { $haveStats = false; + $connectError = ''; $thisDate = false; $thisDateTime = false; $thisMonth = false; @@ -62,7 +63,7 @@ class adminServerStats extends glmServerStatsBandwidthSupport if ($config != false) { // Connect to the bandwidth database - $this->bandwidthDataConnect( + $err = $this->bandwidthDataConnect( $config['db_host'], $config['db_user'], $config['db_pass'], @@ -70,27 +71,34 @@ class adminServerStats extends glmServerStatsBandwidthSupport $config['website'] ); - // Get the current bandwidth stats - $stats = $this->bandwidthGetStats(); + // Check for connection error + if ($err != '') { + $connectError = $err; + } else { - if ($stats != false) { + // Get the current bandwidth stats + $stats = $this->bandwidthGetStats(); - // Build summary info - $thisDate = date('m/d/Y'); - $thisDateTime = strtotime($thisDate); - $thisMonth = date('m/Y'); - $thisMonthTime = strtotime(date('m/01/Y')); - $websiteId = $this->siteId; + if ($stats != false) { - $haveStats = true; + // Build summary info + $thisDate = date('m/d/Y'); + $thisDateTime = strtotime($thisDate); + $thisMonth = date('m/Y'); + $thisMonthTime = strtotime(date('m/01/Y')); + $websiteId = $this->siteId; - } + $haveStats = true; + + } + } } // Compile template data $templateData = array( 'haveStats' => $haveStats, + 'connectError' => $connectError, 'serverStats' => $stats, 'thisDate' => $thisDate, 'thisDateTime' => $thisDateTime, diff --git a/views/adminServerStats.html b/views/adminServerStats.html index 5c31a0a..e1e3a01 100644 --- a/views/adminServerStats.html +++ b/views/adminServerStats.html @@ -115,6 +115,7 @@ {else}

Server Bandwidth has not been configured. Please ask system administrator to configure this plugin.

+

Error: {$connectError}

{/if} {include file='footer.html'}