<?php
/**
 * 紫斑马软件
 * @author afan
 * @link http://www.zibanma.com
 */
if(ZIBANMA_SYS_LINK != 'zibanma_com'){
	die('access deny');
}
abstract class ZibanmaMysql{
	protected $db_host;
	protected $db_user;
	protected $db_password;
	protected $db_selectdb;
	protected $db_prefix;
	protected $db_port;
	protected $result;
	
	abstract public function insert($insert);
	abstract public function update($update);
	abstract public function select($select);
	abstract public function delete($delete);
	
	protected function connect() {
		$conn = mysql_connect($this->db_host.':'.$this->db_port, $this->db_user, $this->db_password) or die("error:mysql_connect");
		mysql_select_db($this->db_selectdb, $conn) or die("error:mysql_select_db");
		mysql_query("set names utf8");
	}
	
	public function execute($sql, $debug = false){
		$sql = str_replace('[prefix]', $this->db_prefix, $sql);
		if($debug == false){
			return mysql_query($sql);
		}else{
			$this->show_sql($sql);
		}
	}
	
	public function get_object($query) {
		return mysql_fetch_object($query);
	}
	
	public function get_array($query){
		return mysql_fetch_array($query);
	}
	
	public function get_rows($sql){
		return mysql_num_rows($this->query($sql));
	}
	
	protected function show_sql($sql){
		echo $sql;
	}
	
	public function get_last_insert_id(){
		return mysql_insert_id();
	}
	
	public function get_prefix(){
		return $this->db_prefix;
	}
	
	public function get_where(){
		return $this->where;
	}
	
	public function query($sql, $type='object', $debug=false){
		$this->result = array();
		if($type == 'object'){
			$execute = $this->execute($sql, $debug);
			while(($row=$this->get_object($execute)) != false){
				$this->result[] = $row;
			}
		}
		if($type == 'array'){
			$execute = $this->execute($sql, $debug);
			while(($row=$this->get_array($execute)) != false){
				$this->result[] = $row;
			}
		}
		return $this->result;
	}
	
	public function __call($name, $value){
		echo 'method nothing';
	}
}
?>