/**
* Emulate ADODB (min) functionalities and at the same time be 2x as fast
* Code used for PHP 4.X
*/
if(!isset($basedir))
{
$cur=getcwd();
$cur=str_replace("\\","/",$cur);
while($cur != "")
{
if(file_exists("$cur/game.php"))
{
$basedir=$cur;
break;
}
$cur=substr($cur,0,strrpos($cur,"/"));
}
}
include_once "$basedir/config/config.inc";
Class database
{
var $conn;
function database($host,$username,$password,$dbname)
{
$this->conn = mysql_connect($host, $username, $password)
or die("Could not connect : " . mysql_error());
mysql_select_db($dbname,$this->conn) or die("Could not select database");
}
function close() { mysql_close($this->conn);}
function execute($query) { $res=new resultset(); return $res->exec($query,$this->conn); }
function getid() { return mysql_insert_id(); }
function SelectLimit($query,$nb,$start) { $res=new resultset(); return $res->exec($query." LIMIT $start,$nb",$this->conn); }
function updateclob($table,$field,$data,$where) { $query="UPDATE $table SET $field=".$this->qstr($data)." WHERE $where"; return mysql_query($query,$this->conn); }
function qstr($str)
{
$res="";
for($i=0;$i < strlen($str);$i++)
{
if(substr($str,$i,1) == "'")
$res.="''";
else
$res.=substr($str,$i,1);
}
return "'$res'";
}
}
class resultset
{
var $result;
var $fields;
var $EOF;
function resultset() {$this->EOF=true;$this->result=null;}
function exec($query,$conn)
{
global $userid,$demoengine;
if($demoengine && isset($userid) && $userid < 3 && strtolower(substr($query,0,1)) != "s")
{
$p=explode(" ",$query);
if($p[1] != "PLAYER")
return false;
}
$this->EOF=false;
$this->result = mysql_query($query,$conn);
if($this->result === FALSE) { $this->result=null;$this->EOF=true; return false; }
if($this->result === TRUE) { $this->result=null;$this->EOF=true; return true; }
$this->fields=mysql_fetch_row($this->result);
if($this->fields === FALSE) { $this->EOF=true; $this->fields=array(); }
return $this;
}
function close() { if($this->result != null) @mysql_free_result($this->result); }
function movenext()
{
$this->fields=mysql_fetch_row($this->result);
if($this->fields === FALSE)
{
$this->fields=array();
$this->EOF=true;
}
}
function fieldcount() { return mysql_num_fields($this->result); }
function fetchfield($col)
{
return mysql_fetch_field($this->result, $col);
}
}
$db=new database($dbhost, $dbuser, $dbpass, $dbname);
?>
Wyszukiwarka
Podobne podstrony:
db conn 4db conn 5db conndb conndb conn 5db conn 5db conn 4db conndb connDBDB AmbershawTOUDB Movie 03 Mysterious Adventuresdb techsharedb polanddb naval techdb revoltdb event listdb strategic bomberwięcej podobnych podstron