<?php
class dbname{
private static $localhost;
private static $root;
private static $pass;
private static $db_name;
public function __construct($localhost,$root,$pass,$db_name){
self::$localhost=$localhost;
self::$root=$root;
self::$pass=$pass;
self::$db_name=$db_name;
self::query();
}
private function query(){
mysql_connect(self::localhost,self::root,self::pass);
mysql_select_db(self::db_name);
mysql_query("set names utf8");
}
public function getAll($sql){
$result = mysql_query($sql);
$rows=array();
while($row = mysql_fetch_assoc($result)){//返回的是多条记录
$rows[]=$row;
}
return $rows;
}
public function getOn($sql){
$result=mysql_query($sql);
@$row=mysql_fetch_row($result); //返回的是一条记录
return $row;
}
}
?>
class dbname{
private static $localhost;
private static $root;
private static $pass;
private static $db_name;
public function __construct($localhost,$root,$pass,$db_name){
self::$localhost=$localhost;
self::$root=$root;
self::$pass=$pass;
self::$db_name=$db_name;
self::query();
}
private function query(){
mysql_connect(self::localhost,self::root,self::pass);
mysql_select_db(self::db_name);
mysql_query("set names utf8");
}
public function getAll($sql){
$result = mysql_query($sql);
$rows=array();
while($row = mysql_fetch_assoc($result)){//返回的是多条记录
$rows[]=$row;
}
return $rows;
}
public function getOn($sql){
$result=mysql_query($sql);
@$row=mysql_fetch_row($result); //返回的是一条记录
return $row;
}
}
?>