mysql操作类(11)
来源:未知 责任编辑:责任编辑 发表时间:2015-10-08 14:15 点击:次
//构造函数
function __construct($db_host,$db_user,$db_pwd,$db_database,$conn,$doding){
$this->db_host=$db_host;
$this->db_user=$db_user;
$this->db_pwd=$db_pwd;
$this->db_database=$db_database;
$this->conn=$conn;
$this->coding=$coding;
$this->connect();
}
//数据库连接
public function connect(){
if($this->conn=="pconn"){
//永久连接
$this->conn=mysql_pconnect($this->db_host,$this->db_user,$this->db_pwd);
}else{
//即使连接
$this->conn=mysql_connect($this->db_host,$this->db_user,$this->db_pwd);
}
if(!mysql_select_db($this->db_database,$this->conn)){
if($this->show_error){
$this->show_error("数据库不可用:",$this->db_database);
}
}
}
//数据库执行语句,可执行查询添加修改删除等任何sql语句
public function query($sql){
if($sql==""){
$this->show_error("sql语句错误:","sql语句为空");
}
$this->sql=$sql;
$result=mysql_query($this->sql,$this->conn);
if(!$result){
if($this->show_error){
$this->show_error("错误sql语句:",$this->sql);
}
}else {
$this->result;
}
return $result;
}
//创建添加新的数据库
public function create_database($database_name){
$database=$database_name;
$sqlDatabase='create database'.$database;
$this->query($sqlDatabase);
}
//查询服务器所有数据库
//将系统数据库与用户分开,更直观的显示
public function show_database(){
$this->query("show databases");
echo "现在有的数据库:".$amount=$this->db_num_rows($rs);
echo "<br>";
$i=1;
while ($row=$this->fetch_array($rs)){
echo "$i $row[Database]";
echo "<br>";
$i++;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>