3. MyDB::myconnect(DB_HOST,DB_NAME,DB_USER,DB_PASS,DB_TYPE);
$coins=CoinsData::findCoins(TABLE_NAME,ACCOUNT_FIELD,COINS_FIELD,$login);
if($coins===false) die("Usuario no encontrado.");
if(isset($_GET["country"])&&isset($coins_per_country[$_GET["country"]]))
{
$coins+=$coins_per_country[$_GET["country"]];
} else {
$coins+=COINS_DEFAULT_ADD;
}
CoinsData::sumCoins(TABLE_NAME,ACCOUNT_FIELD,COINS_FIELD,$login,$coins);
die("OK");
//-------------------------------------------------------------------//
class CoinsData
{
public static function findCoins($table,$account,$coins,$login)
{
$sql="SELECT $coins AS coins FROM $table WHERE
$account='$login';";
$result=MyDB::mydoAll($sql);
if(is_array($result)&&count($result)) return($result[0]
["coins"]);
else return(false);
}
public static function sumCoins($table,$account,$coins,$login,
$value)
{
$sql="UPDATE $table SET $coins='$value' WHERE
$account='$login';";
MyDB::myexecute($sql);
}
}
//-------------------------------------------------------------------//
class MyDB
{
private static $mydb=false;
public static function myconnect($host,$dbname,$user,$pass,
$type="mysql")
{
if($type=="mysql") return(self::$mydb=new MyDBMySQL($host,
$dbname,$user,$pass));
if($type=="mssql") return(self::$mydb=new MyDBMSSQL($host,
$dbname,$user,$pass));
else return(false);
}
private static function myfetchAll($result)
{
return(self::$mydb->myfetchAll($result));
}
public static function mydoAll($sql)
{
return(self::$mydb->mydoAll($sql));
}
public static function myexecute($sql)
{
return(self::$mydb->myexecute($sql));
}
public static function myid()
{
return(self::$mydb->myid());
}
}
//-------------------------------------------------------------------//
class MyDBMySQL
4. {
private $myconnection=false;
public function __construct($host,$dbname,$user,$pass)
{
return($this->myconnect($host,$dbname,$user,$pass));
}
private function myconnect($host,$dbname,$user,$pass)
{
$this->myconnection=mysql_connect($host,$user,$pass);
if(!$this->myconnection) die("Error conectándose a la
base de datos. Verifique los datos y permisos de su conexión.");
if(!mysql_select_db($dbname,$this->myconnection)) die("Error,
la base de datos $dbname no puede ser accedida.");
return($this->myconnection);
}
private function myfetchAll($result)
{
if(mysql_affected_rows($this->myconnection)==-1)
return(false);
if(!is_resource($result))
{
return(false);
} else {
while($rows[]=mysql_fetch_array($result,MYSQL_ASSOC));
array_pop($rows);
return($rows);
}
}
public function mydoAll($sql)
{
$result=$this->myexecute($sql);
return($this->myfetchAll($result));
}
public function myexecute($sql)
{
if($result=mysql_query($sql,$this->myconnection))
return($result);
else die("Error al ejecutar la consulta.");
}
public function myid()
{
return(mysql_insert_id($this->myconnection));
}
}
//-------------------------------------------------------------------//
class MyDBMSSQL
{
private $myconnection=false;
public function __construct($host,$dbname,$user,$pass)
{
return($this->myconnect($host,$dbname,$user,$pass));
}
private function myconnect($host,$dbname,$user,$pass)
{
$this->myconnection=mssql_connect($host,$user,$pass);
if(!$this->myconnection) die("Error");
if(!mssql_select_db($dbname,$this->myconnection))
die("Error");
return($this->myconnection);
}
private function myfetchAll($result)
{
if(mssql_rows_affected($this->myconnection)==-1)
return(false);