<?php //类的声明和使用
class connect_0
{
protected $host = "kiss";
protected $username = "root";
protected $password = "root";
protected $dbname = ["liuyanban","sankea"];
protected $tablename = [["visitor","yhxx","glxx"],["cs_hwsp","cs_mysql11","fromcs","hewei","tanqingyang"]];
public $port = "3306";
public function error(){
echo '<font color="red">'.mysql_error().'</font>';
}
public function lastInsertId(){
return mysql_insert_id();
}
public function query($sql){
$query=mysql_query($sql);
if($query) return true;
else {
$this->error();
return false;
}
}
public function execute(){
$query=mysql_query($sql);
if($query) return mysql_affected_rows();
else {
$this->error();
return false;
}
}
public function one(){
$query=$this->query($sql);
if($query) return mysql_fetch_array($query,MYSQL_ASSOC);
}
public function findall(){
$query=$this->query($sql);
if ($query) {
$rows=[];
while ($row=mysql_fetch_array($query,MYSQL_ASSOC)){
$rows=$row;
}
return $rows;
}
}
public function connect($a=0){
$cn=mysql_connect($this->host,$this->username,$this->password);
if(!is_resource($cn)) $this->error();
$sl = mysql_select_db($this->dbname[$a]);
if(!$sl) $this->error();
$sql = 'set names "utf8"';
$this->query($sql);
}
}
$connect1 = new connect_0();
?>