Example #1
0
 /**
  * Count records by where cond.
  *
  * @param array|string $where
  * @return int
  */
 public function count($where = array())
 {
     if (empty($where)) {
         return $this->db->count($this->_name);
     } else {
         return $this->db->where($where)->count($this->_name);
     }
 }
Example #2
0
 public static function getPageCount($table)
 {
     $Db = new Database();
     $link = $Db->connect();
     $quantity = $Db->count($link, $table);
     //Количество записей в базе данных
     $page_quantity = ceil((int) $quantity / $this->limit);
     //Количество страниц
     return $page_quantity;
 }
Example #3
0
 public function prepare($_qry, $_options = NULL)
 {
     Debug::write("SQL prepare : " . $_qry, 2);
     self::$count = self::$count + 1;
     try {
         // Should be caught through Site.class.php, but still... just in case
         if ($_options === null) {
             return parent::prepare($_qry);
         } else {
             return parent::prepare($_qry, $_options);
         }
     } catch (PDOException $e) {
         Site::error(Site::app_error, "Database error", $GLOBALS['config']['security']['displayExplicitErrors'] === true ? $e->getMessage() : $GLOBALS['config']['errors']['framework']['503']);
     }
 }
Example #4
0
<th><?php 
echo _("Adresse");
?>
 </th>
<th><?php 
echo _("Module");
?>
</th>
<th><?php 
echo _("Résultat");
?>
</th>
</tr>
<TR>
  <?php 
$max = $cn->count();
for ($i = 0; $i < $max; $i++) {
    $r = $cn->fetch($i);
    ?>
<td>
    <?php 
    echo h($r['ac_user']);
    ?>
</td>

<td>
<?php 
    echo $r['fmt_date'];
    ?>
</td>
 public function count()
 {
     return Database::count($this->result);
 }
Example #6
0
 /**
  * @return integer
  */
 public function count()
 {
     return self::$db->count($this->name());
 }
 // $res_color is a template thing for blizzlike templates,
 // makes each row an offset color from the previous
 if ($res_color == 1) {
     $res_color = 2;
 } else {
     $res_color = 1;
 }
 // Define the realm type, and realm number
 $realm_type = $realm_type_def[$result['icon']];
 $realm_num = $result['id'];
 // Check the realm status using the check_port_status function
 if (check_port_status($result['address'], $result['port'], 2) == TRUE) {
     // res image is the up arrow pretty much
     $res_img = 'Online';
     // Get the server population
     $population = $CDB_EXTRA->count("SELECT COUNT(*) FROM `characters` WHERE online=1");
     // Get the server uptime
     $start_time = $DB->selectCell("SELECT `starttime` FROM `uptime` WHERE `realmid`='" . $realm_num . "' ORDER BY `starttime` DESC LIMIT 1");
     $uptime = time() - $start_time;
 } else {
     // Get the result image arrow
     $res_img = 'Offline';
     $population = 0;
     $uptime = 0;
 }
 // Convert uptime into a days / hours / minutes format
 if ($uptime != 0) {
     $uptime = print_time(parse_time($uptime));
 } else {
     $uptime = "N/A";
 }
 $realm_data_explode = explode(';', $data['dbinfo']);
 //DBinfo column:  char_host;char_port;char_username;char_password;charDBname;world_host;world_port;world_username;world_pass;worldDBname
 $mangosALL = array('db_host' => $realm_data_explode['0'], 'db_port' => $realm_data_explode['1'], 'db_username' => $realm_data_explode['2'], 'db_password' => $realm_data_explode['3'], 'db_name' => $realm_data_explode['4']);
 unset($realm_data_explode);
 $CHDB_EXTRA = new Database($mangosALL['db_host'], $mangosALL['db_port'], $mangosALL['db_username'], $mangosALL['db_password'], $mangosALL['db_name']);
 unset($mangosALL);
 // Free up memory.
 $server = array();
 $server['name'] = $data['name'];
 if ((int) $Config->get('fp_realmstatus') == 1) {
     $checkaddress = $data['address'];
     $server['realm_status'] = check_port_status($checkaddress, $data['port'], 0.5) === true ? true : false;
 }
 $changerealmtoparam = array("changerealm_to" => $realmnow_arr['id']);
 if ($Config->get('fp_playersonline') == 1) {
     $server['playersonline'] = $CHDB_EXTRA->count("SELECT count(*) FROM `characters` WHERE online=1");
     $server['onlineurl'] = mw_url('server', 'playersonline', $changerealmtoparam);
 }
 if ($Config->get('fp_serverip') == 1) {
     $server['server_ip'] = $data['address'];
 }
 if ($Config->get('fp_servertype') == 1) {
     $server['type'] = $realm_type_def[$data['icon']];
 }
 if ($Config->get('fp_serverlang') == 1) {
     $server['language'] = $realm_timezone_def[$data['timezone']];
 }
 if ($Config->get('fp_serverpop') == 1) {
     $server['population'] = $CHDB_EXTRA->count("SELECT count(*) FROM `characters` WHERE online=1");
 }
 if ($Config->get('fp_serveract') == 1) {
 private static function isUniqueEntry($Table, $FieldName, $Value, $IDName, $IDValue)
 {
     $ReturnValue = false;
     $DataSet = null;
     $ResultSet = null;
     $QueryString = 'SELECT count(*) FROM `' . DB_PREFIX . $Table . '` WHERE `' . $FieldName . '` = "' . addslashes($Value) . '" AND `' . $IDName . '` != "' . $IDValue . '"';
     if (Database::count($QueryString) == 0) {
         $ReturnValue = true;
     }
     return $ReturnValue;
 }
Example #10
0
 public function backupDatabase($host, $username, $pass, $database)
 {
     // Set execution time to 0 in case the site is huge and will take much time for back-up as default execution time for PHP is 30 seconds. //are the two the same?
     set_time_limit(0);
     ini_set("max_execution_time", 0);
     $backupdir = './ky_backups/';
     if (!is_dir($backupdir)) {
         mkdir($backupdir, 0777, true);
     }
     // Config
     $db = new Database();
     $db->connect($host, $username, $pass, $database);
     $res = $db->query('show databases');
     // Create dump file
     $date = date('Y-m-d_His');
     $dumpfile = $backupdir . 'db-backup_' . $date . ".sql.gz";
     $fp = gzopen($dumpfile, 'w');
     if (!is_resource($fp)) {
         exit('Backup failed: unable to open dump file');
     }
     // Header
     $out = 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";';
     // Write
     gzwrite($fp, $out);
     $out = '';
     // Fetch tables
     $tables = $db->query("SHOW TABLE STATUS");
     if (!$tables) {
         return false;
     }
     $c = 0;
     while ($table = $db->fetch($tables)) {
         $tableName = $table['Name'];
         $tmp = $db->query("SHOW CREATE TABLE `{$tableName}`");
         // Create table
         $create = $db->fetch($tmp);
         $out .= "\n\n" . $create['Create Table'] . ' ;';
         // Clean
         $tmp->closeCursor();
         unset($tmp);
         // Write
         gzwrite($fp, $out);
         $out = '';
         // Rows
         $tmp = $db->query("SHOW COLUMNS FROM `{$tableName}`");
         $rows = array();
         while ($row = $db->fetch($tmp)) {
             $rows[] = $row['Field'];
         }
         // Clean
         $tmp->closeCursor();
         unset($tmp, $row);
         // Get data
         $tmp = $db->query("SELECT * FROM `{$tableName}`");
         $count = $db->count($tmp);
         if ($count > 0) {
             $out .= "\nINSERT INTO `{$tableName}` (`" . implode('`, `', $rows) . "`) VALUES ";
             $i = 1;
             $limit = 1;
             // Fetch data
             while ($entry = $db->fetch($tmp)) {
                 // Create values
                 $out .= "\n(";
                 $tmp2 = array();
                 foreach ($rows as $row) {
                     //$tmp2[] = "'" . mysql_real_escape_string($entry[$row]) . "'";
                     $tmp2[] = "'" . addslashes($entry[$row]) . "'";
                 }
                 $out .= implode(', ', $tmp2);
                 $out .= $i++ === $count ? ');' : ')';
                 if ($limit > 100) {
                     $out .= ";\nINSERT INTO `{$tableName}` (`" . implode('`, `', $rows) . "`) VALUES ";
                     $limit = 1;
                 } else {
                     $out .= $i === $count + 1 ? '' : ',';
                     $limit++;
                 }
                 // Save
                 gzwrite($fp, $out);
                 $out = '';
             }
             // Clean
             $tmp->closeCursor();
             unset($tmp, $tmp2, $i, $count, $entry);
         }
         // Operations counter
         $c++;
     }
     // Close dump file
     gzclose($fp);
     echo "Done! Backup {$c} tables to `{$dumpfile}` (" . filesize($dumpfile) . " o). <br/>";
     return $dumpfile;
 }