Jump to content
MakeWebGames

Recommended Posts

Posted

please iwant db.php file

iwant ask question

can iprogramming engine game by mysql and php only without otherthings pear and some thing like this

Posted

Re: please iwant db.php file

You can build all the code yourself without using pre-existing packages. Now, personally, I would not avoid other packages by principle, you should still check if there isn't something which does what you want as it may spare you a lot of work. Only problem is that most of those packages are under the GNU license or similar, which means you may have some troubles for commercial re-distribution, check carefully the license which comes with packages you may use.

Posted

Re: please iwant db.php file

That's the class I wrote which reflects more or less ADOdb syntax but yet is much faster as it has less functions.

Don't know if this is what you was looking for.

 

<?PHP
Class database
{
var $conn;
var $nbquer;
var $storeQuery;
var $storeID;

function database($host,$username,$password,$dbname)
{
	$this->nbquer=0;
	$this->conn = mysql_connect($host, $username, $password)
	//$this->conn = mysql_pconnect($host, $username, $password)
		or die("Could not connect : " . mysql_error());
	mysql_select_db($dbname,$this->conn) or die("Could not select database");
}

function startStore($id) { $this->storeQuery=true; $this->storeID=$id; $file=fopen("cache/queries_$id.txt","w"); fclose($file); }

function close() { mysql_close($this->conn);}

function execute($query) { if($this->storeQuery) {$file=fopen("cache/queries_".($this->storeID).".txt","a"); fwrite($file,"$query-*@*-"); fclose($file);} $this->nbquer++; $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)
{ return "'".mysql_real_escape_string($str)."'"; }
}

class resultset
{
var $result;
var $fields;
var $EOF;

function resultset() {$this->EOF=true;$this->result=null;}

function exec($query,$conn)
{
	$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("localhost", "your_user", "you_pass", "your_db");
?>
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...