- Timestamp:
- Jul 30, 2013, 11:34:19 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 5 5 minimanager 6 6 mmfpm 7 .settings 8 .buildpath 9 .project
-
- Property svn:ignore
-
trunk/inc/config.sample.php
r690 r712 19 19 'UDBRevision' => '204', 20 20 'ScriptDev2Revision' => '137', 21 'ClientVersion' => '3. 1.3',21 'ClientVersion' => '3.3.5a', 22 22 'DatabaseHost' => 'localhost', 23 23 'DatabaseUser' => 'server1', … … 38 38 ( 39 39 'Charset' => 'utf-8', 40 'Host' => ' george-virt.zdechov.net',40 'Host' => 'localhost', 41 41 'Description' => 'Neoficiální herní server hry World of Warcraft', 42 42 'Keywords' => 'wowserver, world of warcraft, free, wow, server, hof, heroes of fantasy, zdechov, mangos', … … 51 51 'ShowPHPError' => false, 52 52 'ServerFounded' => '1.1.2000', 53 'BankAccount' => ' 670100-2202937132/6210',53 'BankAccount' => '', 54 54 'TableRowPerPage' => 20, 55 55 'DefaultRealmIndex' => 1, -
trunk/inc/database.php
r597 r712 2 2 3 3 // Extended database class 4 // Date: 2009-02-16 5 6 class Database extends mysqli 7 { 8 var $Prefix = ''; 4 // Date: 2011-11-25 5 6 7 class DatabaseResult 8 { 9 var $PDOStatement; 10 var $num_rows = 0; 11 12 function fetch_assoc() 13 { 14 return($this->PDOStatement->fetch(PDO::FETCH_ASSOC)); 15 } 16 17 function fetch_array() 18 { 19 return($this->PDOStatement->fetch(PDO::FETCH_BOTH)); 20 } 21 22 function fetch_row() 23 { 24 return($this->PDOStatement->fetch(PDO::FETCH_NUM)); 25 } 26 } 27 28 class Database 29 { 30 var $Prefix; 31 var $Functions; 32 var $Type; 33 var $PDO; 34 var $Error; 35 var $insert_id; 36 var $LastQuery; 37 var $ShowSQLError; 38 var $ShowSQLQuery; 39 var $LogFile; 40 41 function __construct() 42 { 43 $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()'); 44 $this->Type = 'mysql'; // mysql, pgsql 45 $this->ShowSQLError = false; 46 $this->ShowSQLQuery = false; 47 $this->LogSQLQuery = false; 48 $this->LogFile = dirname(__FILE__).'/../Query.log'; 49 } 50 51 function Connect($Host, $User, $Password, $Database) 52 { 53 if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database; 54 else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host; 55 else $ConnectionString = ''; 56 $this->PDO = new PDO($ConnectionString, $User, $Password); 57 } 58 59 function select_db($Database) 60 { 61 $this->query('USE `'.$Database.'`'); 62 } 9 63 10 64 function query($Query) 11 65 { 12 global $Config; 13 14 if($Config['Web']['ShowSQLQuery'] == true) 15 echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'); 16 $Result = parent::query($Query); 17 if(($this->error != '') and ($Config['Web']['ShowSQLError'] == true)) 18 echo('<div><strong>SQL Error: </strong>'.$this->error.'<br />'.$Query.'</div>'); 19 66 $this->LastQuery = $Query; 67 if($this->ShowSQLQuery == true) 68 echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>'."\n"); 69 if($this->LogSQLQuery == true) 70 file_put_contents($this->LogFile, $Query."\n", FILE_APPEND); 71 $Result = new DatabaseResult(); 72 $Result->PDOStatement = $this->PDO->query($Query); 73 if($Result->PDOStatement) 74 { 75 $Result->num_rows = $Result->PDOStatement->rowCount(); 76 $this->insert_id = $this->PDO->lastInsertId(); 77 } else 78 { 79 $this->Error = $this->PDO->errorInfo(); 80 $this->Error = $this->Error[2]; 81 if(($this->Error != '') and ($this->ShowSQLError == true)) 82 echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>'); 83 throw new Exception('SQL Error: '.$this->Error); 84 } 20 85 return($Result); 21 86 } 22 87 23 88 function select($Table, $What = '*', $Condition = 1) 24 { 89 { 25 90 return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition)); 26 91 } … … 37 102 foreach($Data as $Key => $Value) 38 103 { 39 $Value = strtr($Value, '"', '\"');40 104 $Name .= ',`'.$Key.'`'; 41 if($Value == 'NOW()') $Values .= ','.$Value; 42 else if($Value == 'UUID()') $Values .= ','.$Value; 43 else $Values .= ",'".$Value."'"; 105 if(!in_array($Value, $this->Functions)) 106 { 107 if(is_null($Value)) $Value = 'NULL'; 108 else $Value = $this->PDO->quote($Value); 109 } 110 $Values .= ','.$Value; 44 111 } 45 112 $Name = substr($Name, 1); 46 113 $Values = substr($Values, 1); 47 114 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 115 $this->insert_id = $this->PDO->lastInsertId(); 48 116 } 49 117 … … 53 121 foreach($Data as $Key => $Value) 54 122 { 55 $Value = strtr($Value, '"', '\"'); 56 if($Value != 'NOW()') $Value = "'".$Value."'"; 57 $Values .= ', '.$Key.'='.$Value; 123 if(!in_array($Value, $this->Functions)) 124 { 125 if(is_null($Value)) $Value = 'NULL'; 126 else $Value = $this->PDO->quote($Value); 127 } 128 $Values .= ', `'.$Key.'`='.$Value; 58 129 } 59 130 $Values = substr($Values, 2); … … 67 138 foreach($Data as $Key => $Value) 68 139 { 69 $Value = strtr($Value, '"', '\"'); 140 if(!in_array($Value, $this->Functions)) 141 { 142 if(is_null($Value)) $Value = 'NULL'; 143 else $Value = $this->PDO->quote($Value); 144 } 70 145 $Name .= ',`'.$Key.'`'; 71 if($Value == 'NOW()') $Values .= ','.$Value; 72 else $Values .= ',"'.$Value.'"'; 146 $Values .= ','.$Value; 73 147 } 74 148 $Name = substr($Name, 1); … … 83 157 $this->query('SET NAMES "'.$Charset.'"'); 84 158 } 85 } 86 87 ?> 159 160 function real_escape_string($Text) 161 { 162 return(addslashes($Text)); 163 } 164 } 165 166 function TimeToMysqlDateTime($Time) 167 { 168 if($Time == NULL) return(NULL); 169 else return(date('Y-m-d H:i:s', $Time)); 170 } 171 172 function TimeToMysqlDate($Time) 173 { 174 if($Time == NULL) return(NULL); 175 else return(date('Y-m-d', $Time)); 176 } 177 178 function TimeToMysqlTime($Time) 179 { 180 if($Time == NULL) return(NULL); 181 else return(date('H:i:s', $Time)); 182 } 183 184 function MysqlDateTimeToTime($DateTime) 185 { 186 if($DateTime == '') return(0); 187 $Parts = explode(' ', $DateTime); 188 $DateParts = explode('-', $Parts[0]); 189 $TimeParts = explode(':', $Parts[1]); 190 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 191 return($Result); 192 } 193 194 function MysqlDateToTime($Date) 195 { 196 if($Date == '') return(0); 197 return(MysqlDateTimeToTime($Date.' 0:0:0')); 198 } 199 200 function MysqlTimeToTime($Time) 201 { 202 if($Time == '') return(0); 203 return(MysqlDateTimeToTime('0000-00-00 '.$Time)); 204 } -
trunk/inc/realm.php
r695 r712 13 13 $DbResult = $this->Database->query('SELECT * FROM Realm WHERE Id='.$Id.' AND Enabled=1'); 14 14 $this->Data = $DbResult->fetch_assoc(); 15 $this->CharactersDatabase = new Database($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseCharacters']); 15 $this->CharactersDatabase = new Database(); 16 $this->CharactersDatabase->Connect($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseCharacters']); 16 17 $this->CharactersDatabase->select_db($this->Data['DatabaseCharacters']); 17 if($this->CharactersDatabase->connect_error)18 {19 die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->Database->connect_error);20 }18 //if($this->CharactersDatabase->connect_error) 19 //{ 20 // die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->Database->connect_error); 21 //} 21 22 $this->CharactersDatabase->charset($this->Config['Database']['Charset']); 22 23 23 $this->MangosDatabase = new Database($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseMangos']); 24 $this->MangosDatabase = new Database(); 25 $this->MangosDatabase->Connect($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseMangos']); 24 26 $this->MangosDatabase->select_db($this->Data['DatabaseMangos']); 25 if($this->MangosDatabase->connect_error)26 {27 die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->MangosDatabase->connect_error);28 }27 //if($this->MangosDatabase->connect_error) 28 //{ 29 // die('Přihlášení k databázi realmu '.$this->Id.' selhalo: '.$this->MangosDatabase->connect_error); 30 //} 29 31 $this->MangosDatabase->charset($this->Config['Database']['Charset']); 30 32 } -
trunk/inc/server.php
r697 r712 14 14 $this->Id = $Id; 15 15 $DbResult = $this->Database->query('SELECT * FROM Logon WHERE Id='.$Id.' AND Enabled=1' ); 16 $this->Data = $DbResult->fetch_assoc(); 17 $this->ServerDatabase = new Database($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseRealmd']); 18 $this->ServerDatabase->select_db($this->Data['DatabaseRealmd']); 19 if($this->ServerDatabase->connect_error) 16 if($DbResult->num_rows == 1) 20 17 { 21 die('Přihlášení k databázi serveru '.$this->Id.' selhalo: '.$this->ServerDatabase->connect_error); 22 } 23 $this->ServerDatabase->charset($this->Config['Database']['Charset']); 18 $this->Data = $DbResult->fetch_assoc(); 19 $this->ServerDatabase = new Database(); 20 $this->ServerDatabase->Connect($this->Data['DatabaseHost'], $this->Data['DatabaseUser'], $this->Data['DatabasePassword'], $this->Data['DatabaseRealmd']); 21 $this->ServerDatabase->select_db($this->Data['DatabaseRealmd']); 22 //if($this->ServerDatabase->connect_error) 23 //{ 24 // die('Přihlášení k databázi serveru '.$this->Id.' selhalo: '.$this->ServerDatabase->connect_error); 25 //} 26 $this->ServerDatabase->charset($this->Config['Database']['Charset']); 27 } else throw new Exception('Záznam pro přihlašovací server id '.$Id.' nenalezen!'); 24 28 } 25 29 -
trunk/inc/system.php
r695 r712 47 47 function OpenLogonServerDatabase() 48 48 { 49 $Database = new Database($this->Config['Mangos']['DatabaseHost'], $this->Config['Mangos']['DatabaseUser'], $this->Config['Mangos']['DatabasePassword'], $this->Config['Mangos']['DatabaseRealmd']); 49 $Database = new Database(); 50 $Database->Connect($this->Config['Mangos']['DatabaseHost'], $this->Config['Mangos']['DatabaseUser'], $this->Config['Mangos']['DatabasePassword'], $this->Config['Mangos']['DatabaseRealmd']); 50 51 if(mysqli_connect_error()) 51 52 { … … 58 59 function OpenWebDatabase() 59 60 { 60 $Database = new Database($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']); 61 $Database = new Database(); 62 $Database->Connect($this->Config['Database']['Host'], $this->Config['Database']['User'], $this->Config['Database']['Password'], $this->Config['Database']['Database']); 61 63 if(mysqli_connect_error()) 62 64 {
Note:
See TracChangeset
for help on using the changeset viewer.