标签:
<?php
header("content-type: text/html; charset=utf-8");
/*__construct()初始化
*php+mySql类
*/
class mysql{
private $host;
private $name;
private $pass;
private $table;//数据库表
private $ut;
//初始化函数
function __construct($host,$name,$pass,$table,$ut){
$this->host = $host;
$this->name = $name;
$this->pass = $pass;
$this->table = $table;
$this->ut = $ut;
$this->connect();
}
//建立连接数据库的函数
function connect(){
//mysql_connect($this->host,$this->name,$this->pass) or die (mysql_error());
$link = mysql_connect($this->host,$this->name,$this->pass) or die (mysql_error());
// echo "连接成功";
mysql_select_db($this->table,$link) or die ("没有数据库".$this->table);
mysql_query("SET NAMES".$this->ut); //这种插入会乱码.因为编码格式要加引号
mysql_query("SET NAMES ‘$this->ut‘");
}
//执行mysql语句函数
function query($v){
return mysql_query($v);
}
//封装错误提示信息
function errora(){
return mysql_error();
}
//====================
function fn_insert($table,$name,$value){
//表名,字段名,字段值
$this->query("insert into $table ($name) value ($value)");
}
}
$db = new mysql("localhost","root","","laok","utf8");
$db->fn_insert(‘test‘,‘id,uid,regdate,remark‘,"‘‘,‘我插入的信息23‘,now(),‘‘");
?>
标签:
原文地址:http://www.cnblogs.com/laok/p/4582148.html