超简单php mysql数据库查询类
本文章为你免费提供一款漂亮的超简单php mysql数据库查询类哦
<?php
private $host; //主机名称:一般是localhost
private $root; //mysql帐号:一般是root
private $password; //数据库密码:一般为空
private $datebase; //数据库名称:一般自己定义
private $ut; //编码问题如:utf-8gbk
//初始化这个类的变量
function __construct($host, $root, $password, $datebase, $ut) {
$this->host = $host; //初始化主机名称
$this->root = $root; //初始化数据库帐号
$this->password = $password; //初始化数据库密码
$this->datebase = $datebase; //初始化数据库名称
$this->conn(); //初始化连接数据库的方法
$this->ut = $ut; //初始化编码
}
//常用连接数据库的方法
function conn() {
$conn = mysql_connect($this->host, $this->root, $this->password) or die($this->error());
mysql_select_db($this->datebase, $conn) or die("没有这个数据库:" . $this->datebase);
mysql_query("SET NAMES '$this->ut'");
}
//常用传送sql到数据库的方法
function query($v) {
return mysql_query($v);
}
//常用函数查看数据
function fetch_row($query) {
return mysql_fetch_row($query);
}
//常用错误的方法
function error() {
return mysql_error();
}
//常用关闭数据库的方法
function close() {
return mysql_close();
}
}教程链接:http://www.phprm.com/code/9c480319e159cdd6df6af7a8c6ed8d7d.html
随意转载~但请保留教程地址★