Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- function __construct()
- {
- $connections = array('logon'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'logon'),
- 'website'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'website'),
- 'vote'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'vote')
- );
- $realms = array('Warground'=>array('char'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'warground_char'),
- 'world'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'warground_world'),
- 'max_online'=>'200')
- 'Destruction'=>array('char'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'destruction_char'),
- 'world'=>array('user'=>'root',
- 'pass'=>'lolpwned',
- 'host'=>'127.0.0.1',
- 'db_name'=>'destructionworld'),
- 'max_online'=>'200')
- );
- $this->connections = $connections;
- $this->realms = $realms;
- }
- function get_stats()
- {
- foreach( $this->realms as $realm => $db_array )
- {
- $horde = 0;
- $alliance = 0;
- $i = 0;
- $char = $db_array['char'];
- $con = $this->con($char, true);
- $sql = 'select race from characters where online="1"';
- $array = $this->query_to_array( $sql );
- foreach( $array as $k=>$v )
- {
- $race = $v['race'];
- if( $race == "2" || $race == "5" || $race == "6" || $race == "8" || $race == "10" )
- {
- $horde = $horde+1;
- }
- else { $alliance = $alliance+1; }
- }
- $count_online = count( $array );
- $max_online = $db_array['max_online'];
- $percent = $count_online / $max_online;
- $percent = round( $percent * 100 );
- echo('
- <center><span class="stat_head">'.$realm.'</span>
- <center><span class="players_online">'.$count_online.'/'.$max_online.'</span></center>
- <div class="bar_bg"><div class="active_bar" style="width:'.$percent.'%;"></div></div>
- <span style="color:red;">[ H: '.$horde.' ] </span>
- <span style="color:lime;">[ A: '.$alliance.' ]</span>
- ');
- }
- }
- function con( $db, $realm=false ) {
- if(!$realm)
- {
- $user = $this->connections[$db]['user'];
- $pass = $this->connections[$db]['pass'];
- $host = $this->connections[$db]['host'];
- $data = $this->connections[$db]['db_name'];
- }
- else{
- $user = $db['user'];
- $pass = $db['pass'];
- $host = $db['host'];
- $data = $db['db_name'];
- //echo $user."::".$pass."::".$host."::".$data;
- }
- $con = mysql_connect( $host, $user, $pass ) or die('Error: cannot connect to database!');
- $con = mysql_select_db( $data, $con );
- return $con;
- }
- function query( $sql, $con = NULL ) {
- if( $con == NULL )
- {
- $result = mysql_query( $sql ) or die ('Error: check query string!'.mysql_error());
- }
- else
- {
- $result = mysql_query( $sql, $con ) or die ('Error: check query string!'.mysql_error());
- }
- return $result;
- }
- function count_char( $char, $realm, $id )
- {
- $chardb = $this->realms[$realm]['char'];
- $this->con( $chardb, true );
- $char = 'select guid,name from characters where guid="'.$char.'" and account="'.$id.'"';
- $result_char = $this->query( $char );
- $count = $this->num_rows( $result_char );
- return $count;
- }
- function num_rows( $resource ) {
- return @mysql_num_rows( $resource );
- }
- function query_to_array( $query ) {
- if( $con != NULL )
- {
- $result = mysql_query( $query ) or die ('Error: check query string!'.mysql_error());
- }
- else {
- $result = mysql_query( $query ) or die ('Error: check query string!'.mysql_error());
- }
- $i=0;
- while( $row = mysql_fetch_array( $result ) )
- {
- $array[$i] = $row;
- $i++;
- }
- return $array;
- }
- function ReturnObject( $result )
- {
- $return = mysql_fetch_object( $result );
- return $return or die('Error: object could not be retrieved!');
- }
- function update_sid( $username )
- {
- $this->con( 'logon' );
- $sid = md5(uniqid(rand(), true));
- $_SESSION['sid'] = $sid;
- $sql = 'update account set sid="'.$sid.'" where username="'.$username.'"';
- $this->query( $sql );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement