<?php
class mysql{
//private 私有属性关键字
private $host;
private $name;
private $pass;
private $table;
private $ut;
function __construct($host,$name,$pass,$table){//初始化方法名
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
$this->connect();
}
function connect(){//连接数据库
$link=mysql_connect($this->host,$this->name,$this->pass) or die(mysql_error());
mysql_select_db($this->table,$link) or die("没有该数据库:"。$this->table);
mysql_query("set names '$this->ut'");
}
function query(){//常用的类进行封装,方便修改
return mysql_query();//
}
function error(){//常用的类进行封装,方便修改
return mysql_error();
}
//===========================
function fn_insert($table,$name,$value){//封装insert
$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql('localhost','root','','message','GBK');//连接数据库
$db->fn_insert('test','id,title,dates',"'','我插入的信息',now()");//插入数据
?>
class mysql{
//private 私有属性关键字
private $host;
private $name;
private $pass;
private $table;
private $ut;
function __construct($host,$name,$pass,$table){//初始化方法名
$this->host=$host;
$this->name=$name;
$this->pass=$pass;
$this->table=$table;
$this->ut=$ut;
$this->connect();
}
function connect(){//连接数据库
$link=mysql_connect($this->host,$this->name,$this->pass) or die(mysql_error());
mysql_select_db($this->table,$link) or die("没有该数据库:"。$this->table);
mysql_query("set names '$this->ut'");
}
function query(){//常用的类进行封装,方便修改
return mysql_query();//
}
function error(){//常用的类进行封装,方便修改
return mysql_error();
}
//===========================
function fn_insert($table,$name,$value){//封装insert
$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql('localhost','root','','message','GBK');//连接数据库
$db->fn_insert('test','id,title,dates',"'','我插入的信息',now()");//插入数据
?>