Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)归海一刀
published in(发表于) 2014/2/17 7:45:53
用PHP操作MySql数据库(DB类)_[PHP教程]

用PHP操作MySql数据库(DB类)_[PHP教程]
/*
* mysql数据库 DB类
* @package db
* @author yytcpt(无影)
* @version 2008-03-27
* @copyrigth http://www.d5s.cn/
*/
class db {
var connection_id = "";
var pconnect = 0;
var shutdown_queries = array();
var queries = array();
var query_id = "";
var query_count = 0;
var record_row = array();
var failed = 0;
var halt = "";
var query_log = array();
function connect(db_config){
if (this->pconnect){
this->connection_id = mysql_pconnect(db_config["hostname"], db_config["username"], db_config["password"]);
}else{
this->connection_id = mysql_connect(db_config["hostname"], db_config["username"], db_config["password"]);
}
if ( ! this->connection_id ){
this->halt("Can not connect MySQL Server");
}
if ( ! @mysql_select_db(db_config["database"], this->connection_id) ){
this->halt("Can not connect MySQL Database");
}
if (db_config["charset"]) {
@mysql_unbuffered_query("SET NAMES ’".db_config["charset"]."’");
}
return true;
}
//发送SQL 查询,并返回结果集
function query(query_id, query_type=’mysql_query’){
this->query_id = query_type(query_id, this->connection_id);
this->queries[] = query_id;
if (! this->query_id ) {
this->halt("查询失败:\nquery_id");
}
this->query_count++;
this->query_log[] = str;
return this->query_id;
}
//发送SQL 查询,并不获取和缓存结果的行
function query_unbuffered(sql=""){
return this->query(sql, ’mysql_unbuffered_query’);
}
//从结果集中取得一行作为关联数组
function fetch_array(sql = ""){
if (sql == "") sql = this->query_id;
this->record_row = @mysql_fetch_array(sql, MYSQL_ASSOC);
return this->record_row;
}



If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759