码迷,mamicode.com
首页 > 数据库 > 详细

简单的类php和mysql

时间:2015-06-17 00:23:02      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:


<?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(),‘‘");

?>

简单的类php和mysql

标签:

原文地址:http://www.cnblogs.com/laok/p/4582148.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!