phpwind中的數(shù)據(jù)庫(kù)操作類
更新時(shí)間:2007年01月02日 00:00:00 作者:
<?php
/*來源:phpwind.net*/
Class DB {
var $query_num = 0;
function DB($dbhost, $dbuser, $dbpw, $dbname, $pconnect = 0) {
$this->connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect);
}
function connect($dbhost, $dbuser, $dbpw, $dbname, $pconnect = 0) {
$pconnect==0 ? @mysql_connect($dbhost, $dbuser, $dbpw) : @mysql_pconnect($dbhost, $dbuser, $dbpw);
mysql_errno()!=0 && $this->halt("Connect($pconnect) to MySQL failed");
if($this->server_info() > '4.1' && $GLOBALS['charset']){
mysql_query("SET NAMES '".$GLOBALS['charset']."'");
}
if($this->server_info() > '5.0'){
mysql_query("SET sql_mode=''");
}
if($dbname) {
if (!@mysql_select_db($dbname)){
$this->halt('Cannot use database');
}
}
}
function close() {
return mysql_close();
}
function select_db($dbname){
if (!@mysql_select_db($dbname)){
$this->halt('Cannot use database');
}
}
function server_info(){
return mysql_get_server_info();
}
function query($SQL,$method='') {
$GLOBALS['PW']=='pw_' or $SQL=str_replace('pw_',$GLOBALS['PW'],$SQL);
if($method=='U_B' && function_exists('mysql_unbuffered_query')){
$query = mysql_unbuffered_query($SQL);
}else{
$query = mysql_query($SQL);
}
$this->query_num++;
//echo $SQL.'<br>'.$this->query_num.'<br>';
if (!$query) $this->halt('Query Error: ' . $SQL);
return $query;
}
function get_one($SQL){
$query=$this->query($SQL,'U_B');
$rs =& mysql_fetch_array($query, MYSQL_ASSOC);
return $rs;
}
function pw_update($SQL_1,$SQL_2,$SQL_3){
$rt=$this->get_one($SQL_1);
if($rt){
$this->update($SQL_2);
} else{
$this->update($SQL_3);
}
}
function update($SQL) {
$GLOBALS['PW']=='pw_' or $SQL=str_replace('pw_',$GLOBALS['PW'],$SQL);
if($GLOBALS['db_lp']==1){
if(substr($SQL,0,7)=='REPLACE'){
$SQL=substr($SQL,0,7).' LOW_PRIORITY'.substr($SQL,7);
} else{
$SQL=substr($SQL,0,6).' LOW_PRIORITY'.substr($SQL,6);
}
}
if(function_exists('mysql_unbuffered_query')){
$query = mysql_unbuffered_query($SQL);
}else{
$query = mysql_query($SQL);
}
$this->query_num++;
//echo $SQL.'<br>'.$this->query_num.'<br>';
if (!$query) $this->halt('Update Error: ' . $SQL);
return $query;
}
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}
function affected_rows() {
return mysql_affected_rows();
}
function num_rows($query) {
$rows = mysql_num_rows($query);
return $rows;
}
function free_result($query) {
return mysql_free_result($query);
}
function insert_id() {
$id = mysql_insert_id();
return $id;
}
function halt($msg='') {
require_once(R_P.'require/db_mysql_error.php');
new DB_ERROR($msg);
}
}
?>
您可能感興趣的文章:
- php mysql數(shù)據(jù)庫(kù)操作類
- 簡(jiǎn)單的php數(shù)據(jù)庫(kù)操作類代碼(增,刪,改,查)
- 全新的PDO數(shù)據(jù)庫(kù)操作類php版(僅適用Mysql)
- ezSQL PHP數(shù)據(jù)庫(kù)操作類庫(kù)
- php實(shí)現(xiàn)mysql數(shù)據(jù)庫(kù)操作類分享
- PHP數(shù)據(jù)庫(kù)操作之基于Mysqli的數(shù)據(jù)庫(kù)操作類庫(kù)
- PHP實(shí)現(xiàn)PDO的mysql數(shù)據(jù)庫(kù)操作類
- php下mysql數(shù)據(jù)庫(kù)操作類(改自discuz)
- PHP輕量級(jí)數(shù)據(jù)庫(kù)操作類Medoo增加、刪除、修改、查詢例子
- PHP實(shí)現(xiàn)的MongoDB數(shù)據(jù)庫(kù)操作類分享
- 支持php4、php5的mysql數(shù)據(jù)庫(kù)操作類
- PHP簡(jiǎn)單數(shù)據(jù)庫(kù)操作類實(shí)例【支持增刪改查及鏈?zhǔn)讲僮鳌?/a>
相關(guān)文章
php實(shí)現(xiàn)將普通數(shù)據(jù)轉(zhuǎn)化為json數(shù)據(jù)
在日常的開發(fā)工作中免不了要寫接口,json格式文本的輸出是制作接口必須掌握的,所以本文主要為大家詳細(xì)介紹了php如何將普通數(shù)據(jù)轉(zhuǎn)化為json數(shù)據(jù),需要的可以參考下2023-11-11PHP使用PHPExcel實(shí)現(xiàn)批量上傳到數(shù)據(jù)庫(kù)的方法
下面小編就為大家?guī)硪黄狿HP使用PHPExcel實(shí)現(xiàn)批量上傳到數(shù)據(jù)庫(kù)的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06php session實(shí)現(xiàn)多級(jí)目錄存放實(shí)現(xiàn)代碼
這篇文章主要介紹了php session實(shí)現(xiàn)多級(jí)目錄存放實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-02-02PHP實(shí)現(xiàn)簡(jiǎn)單的新聞發(fā)布系統(tǒng)實(shí)例
這篇文章主要介紹了PHP實(shí)現(xiàn)簡(jiǎn)單的新聞發(fā)布系統(tǒng),涉及php實(shí)現(xiàn)新聞發(fā)布系統(tǒng)的sql查詢、插入、更新等完整操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07php流量統(tǒng)計(jì)功能的實(shí)現(xiàn)代碼
用php實(shí)現(xiàn)的流量統(tǒng)計(jì)功能代碼,本代碼僅供學(xué)習(xí)交流,其中必有不妥之處。請(qǐng)見諒2012-09-09PHP中使用hidef擴(kuò)展代替define提高性能
這篇文章主要介紹了PHP中使用hidef擴(kuò)展代替define提高性能,本文著重測(cè)試hidef的性能,同時(shí)介紹了安裝方法和使用示例,需要的朋友可以參考下2015-04-04