Example #1
0
<?php

include_once './dbInstance.php';
include_once './dbConfig.php';
$mDbInstance = new dbInstance();
$mDbInstance->dbConnect();
$mDbInstance->dbUpdate(19, 'mariajo');
$mDbInstance->dbDelete(15);
$mDbInstance->dbDisconnect();
 // Get all 'registration IDs' from database
 $userRegIds = $mDbInstance->dbGetAllUsers();
 $mGcmInstance = new gcmInstance();
 for ($i = 0; $i < mysqli_num_rows($userRegIds); $i++) {
     $userArray = mysqli_fetch_row($userRegIds);
     // Send message to devices and getting back a new 'registration ID' in case it has been updated by the GCM server
     $gcmSuccess = $mGcmInstance->sendNotification($userArray, $message);
     if ($gcmSuccess) {
         // If the return value is not '', the entry has to be updated ('dbInsert' with a third argument)
         if ($mGcmInstance->newId != '') {
             //echo 'From dbInstance, result: ' . $mGcmInstance->newId . PHP_EOL;
             $resultQuery = $mDbInstance->dbInsert($mGcmInstance->newId, "", $userArray[0]);
             echo 'Update query result: ' . $resultQuery . PHP_EOL;
             // If '0' is retrieved, no update has been performed, and therefore the entry is repeated
             if ($resultQuery == 0) {
                 $resultQuery = $mDbInstance->dbDelete($userArray[0]);
                 echo 'Entry deleted' . PHP_EOL;
             }
         }
     } else {
         if ($mGcmInstance->error != '') {
             echo 'From dbInstance, error: ' . $mGcmInstance->error . PHP_EOL;
             $resultQuery = $mDbInstance->dbDelete($userArray[0]);
             echo 'Entry deleted: ' . $resultQuery . PHP_EOL;
         }
     }
     // Reset 'gcmInstance' values for next iteration
     $mGcmInstance->newId = '';
     $mGcmInstance->error = '';
 }
 mysqli_free_result($userRegIds);