Location: PHPKode > projects > Skrupel User Game Administration > include/db_mysql.inc.php
<?php

global $db_con;

function connect_db(){
        global $server;
        global $login;
        global $password;
        global $database;
        global $db_con;
        
        if(is_resource($db_con)){
                return $db_con;
        }
        else{
                $db_con = mysql_connect($server, $login, $password);
                if(!$db_con){
                        echo "db_con false, connect failed";
                        die("session halted.");
                }
                
                if (!mysql_query(sprintf("use %s",$database),$db_con))
		{
			echo "cannot use database ".$database;
		}
		
		return $db_con;
        }
}

class db_sql
{
        var $server   = "";
        var $database = "";
        var $login    = "";
        var $password = "";

        var $link_id  = 0;
        var $query_id = 0;
        var $record   = array();
        var $row;

        var $errno    = 0;
        var $error    = "";

        function db_sql(){
                $this->link_id = connect_db();
        }
        
	function halt($msg)
	{
		printf("<b>database error:</b> %s<br>\n", $msg);
		printf("<b>mysql error</b>: %s (%s)<br>\n",
		$this->errno,
		$this->error);
		die("session halted.");
	}

	function query($query_string)
	{
		$this->query_id = mysql_query($query_string,$this->link_id);
		$this->row   = 0;
		$this->errno = mysql_errno();
		$this->error = mysql_error();
		if (!$this->query_id)
		{
			$this->halt("invalid sql: ".$query_string);
		}

		return $this->query_id;
	}

	function next($data = false)
	{
		$this->record = mysql_fetch_array($this->query_id);
		$this->row   += 1;
		$this->errno = mysql_errno();
		$this->error = mysql_error();

		$stat = is_array($this->record);
		
	        if($data == true){
	                return $this->record;
	        }
	        else{
		        return $stat;
		}
	}
	
	function value($row){
	        if(is_array($this->record)){
	                return ($this->record[$row]);
	        }
	        else{
	                return false;
	        }
	}
	
	function num_rows()
	{
		return mysql_num_rows($this->query_id);
	}
	
	function close()
	{
		mysql_close($this->link_id);
	}
	
	
}
?>
Return current item: Skrupel User Game Administration