<?php
class Mysql{
public $webName='localhost';
public $port=':3306';
public $adminName='root';
public $pwd='';
public $number='UTF8';
public $item='myitem';
public $conn;
public function __construct(){
$this->webName=defined("WEB_NAME")?WEB_NAME:$this->webName;
$this->port= defined("PORT")?PORT:$this->port;
$this->adminName=defined("ADMIN_NAME")?ADMIN_NAME:$this->adminName;
$this->pwd= defined("PWD")?PWD:$this->pwd;
$this->number=defined("NUMBER")?NUMBER:$this->number;
$this->item=defined("ITEM")?ITEM:$this->item;
$conn=@mysql_connect($this->webName.$this->port,$this->adminName, $this->pwd);
$db= mysql_select_db($this->item,$conn);
mysql_query('set names '.$this->number,$conn);
mysql_query('SET character_set_client=binary',$conn);
$this->conn=$conn;
}
public function query($sql,$types='list'){
$conn= $this->conn;
$str=strtoupper(trim(substr($sql,0,6)));
$search=mysql_query($sql,$conn);
if($str=='SELECT'){
if($types=='list'){
$data=array();
while($row=mysql_fetch_assoc($search)) {
$data[]=$row;
}
return $data;
}else{
$row = mysql_fetch_assoc($search);
return $row;
}
}else if($str=='INSERT'){
return mysql_insert_id();
}else{
return mysql_affected_rows();
}
}
}
class Mysql{
public $webName='localhost';
public $port=':3306';
public $adminName='root';
public $pwd='';
public $number='UTF8';
public $item='myitem';
public $conn;
public function __construct(){
$this->webName=defined("WEB_NAME")?WEB_NAME:$this->webName;
$this->port= defined("PORT")?PORT:$this->port;
$this->adminName=defined("ADMIN_NAME")?ADMIN_NAME:$this->adminName;
$this->pwd= defined("PWD")?PWD:$this->pwd;
$this->number=defined("NUMBER")?NUMBER:$this->number;
$this->item=defined("ITEM")?ITEM:$this->item;
$conn=@mysql_connect($this->webName.$this->port,$this->adminName, $this->pwd);
$db= mysql_select_db($this->item,$conn);
mysql_query('set names '.$this->number,$conn);
mysql_query('SET character_set_client=binary',$conn);
$this->conn=$conn;
}
public function query($sql,$types='list'){
$conn= $this->conn;
$str=strtoupper(trim(substr($sql,0,6)));
$search=mysql_query($sql,$conn);
if($str=='SELECT'){
if($types=='list'){
$data=array();
while($row=mysql_fetch_assoc($search)) {
$data[]=$row;
}
return $data;
}else{
$row = mysql_fetch_assoc($search);
return $row;
}
}else if($str=='INSERT'){
return mysql_insert_id();
}else{
return mysql_affected_rows();
}
}
}