]> git.mxchange.org Git - mailer.git/blobdiff - inc/stats-functions.php
Adding of network advert types partly finished, hard-coded table type fixed to dynamic
[mailer.git] / inc / stats-functions.php
index 1e4b5dac22d7634abdd1ca86203bf1db3209ce2f..e38e6114b7414ca749adc51428de4cfe25cea69c 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 10/25/2009 *
- * ===============                              Last change: 10/25/2009 *
+ * Mailer v0.2.1-FINAL                                Start: 10/25/2009 *
+ * ===================                          Last change: 10/25/2009 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : stats-functions.php                              *
@@ -80,7 +80,7 @@ function incrementStatsEntry ($entry, $amount=1) {
 // Getter for stats
 function getStatsEntry ($entry) {
        // Default is zero
-       $stats = 0;
+       $stats = '0';
 
        // Is it there?
        if (isStatsEntrySet($entry)) {
@@ -99,6 +99,9 @@ function setStatsEntry ($entry, $value) {
 
 // Loads stats table
 function loadStatsTable () {
+       // Check if the link is up
+       if (!SQL_IS_LINK_UP()) return false;
+
        // Do we have it there for today?
        if (!isStatsTableCreated()) {
                // Then create a default one
@@ -120,6 +123,9 @@ function loadStatsTable () {
 
 // Checks if the the statistics table is created
 function isStatsTableCreated () {
+       // Check if the link is up
+       if (!SQL_IS_LINK_UP()) return false;
+
        // Ask for it
        $result = SQL_QUERY_ESC("SHOW TABLES LIKE '{?_MYSQL_PREFIX?}_stats_%s'",
                array(date('Ymd', time())), __FUNCTION__, __LINE__);
@@ -130,6 +136,9 @@ function isStatsTableCreated () {
 
 // Create the dummy table
 function createStatsTable () {
+       // Check if the link is up
+       if (!SQL_IS_LINK_UP()) return false;
+
        // Create it here
        $result = SQL_QUERY_ESC("CREATE TABLE IF NOT EXISTS `{?_MYSQL_PREFIX?}_stats_%s` (
 `stats_entry` VARCHAR(100) NOT NULL DEFAULT '',
@@ -141,16 +150,19 @@ PRIMARY KEY (`stats_entry`)
 
 // Write all entries to the table
 function writeStatsTable () {
+       // Check if the link is up
+       if (!SQL_IS_LINK_UP()) return false;
+
        // Empty the table first
        SQL_QUERY_ESC("TRUNCATE `{?_MYSQL_PREFIX?}_stats_%s`",
                array(date('Ymd', time())), __FUNCTION__, __LINE__);
 
        // Begin the SQL command
-       $sql = sprintf("INSERT INTO `{?_MYSQL_PREFIX?}_stats_%s` (`stats_entry`,`stats_value`) VALUES ",
+       $sql = sprintf("REPLACE INTO `{?_MYSQL_PREFIX?}_stats_%s` (`stats_entry`,`stats_value`) VALUES ",
                date('Ymd', time()));
 
        // Add all entries to the final query
-       foreach ($GLOBALS['stats'] as $entry=>$value) {
+       foreach ($GLOBALS['stats'] as $entry => $value) {
                $sql .= sprintf("('%s', %s),", $entry, bigintval($value));
        } // END - foreach