最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Mysql數(shù)據(jù)庫(kù)操作類( 1127版,提供源碼下載 )

 更新時(shí)間:2010年12月02日 22:04:55   作者:  
Mysql數(shù)據(jù)庫(kù)操作類,學(xué)習(xí)php的朋友可以參考下。
Mysql.class.php 下載
復(fù)制代碼 代碼如下:

<?php
class Mysql {
private $db_host; //主機(jī)地址
private $db_user; //用戶名
private $db_pass; //連接密碼
private $db_name; //名稱
private $db_charset; //編碼
private $conn;
public $debug=false;//調(diào)試開關(guān),默認(rèn)關(guān)閉
private $query_id; //用于判斷sql語句是否執(zhí)行成功
private $result; //結(jié)果集
private $num_rows; //結(jié)果集中行的數(shù)目,僅對(duì)select有效
private $insert_id; //上一步 INSERT 操作產(chǎn)生的 ID
// 構(gòu)造/析構(gòu)函數(shù)
function __construct ($db_host,$db_user,$db_pass,$db_name,$db_charset,$conn) {
$this->db_host = $db_host ;
$this->db_user = $db_user ;
$this->db_pass = $db_pass ;
$this->db_name = $db_name ;
$this->db_charset = $db_charset ;
$this->conn = $conn ;
$this->connect();
}
function __destruct () {
@mysql_close($this->conn);
}
// 連接/選擇數(shù)據(jù)庫(kù)
public function connect () {
if ($this->conn == 'pconn') {
@$this->conn = mysql_pconnect($this->db_host,$this->db_user,$this->db_pass);
} else {
@$this->conn = mysql_connect($this->db_host,$this->db_user,$this->db_pass);
}
if (!$this->conn) {
$this->show_error('數(shù)據(jù)庫(kù)-連接失?。河脩裘蛎艽a錯(cuò)誤!');
}
if (!@mysql_select_db($this->db_name,$this->conn)) {
$this->show_error("數(shù)據(jù)庫(kù)-選擇失?。簲?shù)據(jù)庫(kù) $this->db_name 不可用");
}
mysql_query("SET NAMES $this->db_charset");
return $this->conn;
}
// query方法
public function query ($sql) {
if ($this->query_id) $this->free_result();
$this->query_id = @mysql_query($sql,$this->conn);
if (!$this->query_id) $this->show_error("SQL語句 <b>\"$sql\"</b> 執(zhí)行時(shí)遇到錯(cuò)誤");
return $this->query_id;
}
// 顯示詳細(xì)錯(cuò)誤信息
public function show_error ($msg) {
if($this->debug){
$errinfo = mysql_error();
echo "錯(cuò)誤:$msg <br/> 返回:$errinfo<p>";
}else{
echo '<p>出現(xiàn)錯(cuò)誤!<p>';
}
}
// 獲得query執(zhí)行成功與否的信息
public function get_query_info($info){
if ($this->query_id) {
echo $info;
}
}
// 查詢所有
public function findall ($table_name) {
$this->query("select * from $table_name");
}
// mysql_fetch_array
public function fetch_array () {
if ($this->query_id) {
$this->result = mysql_fetch_array($this->query_id);
return $this->result;
}
}
// ......
public function fetch_assoc () {
if ($this->query_id) {
$this->result = mysql_fetch_assoc($this->query_id);
return $this->result;
}
}
public function fetch_row () {
if ($this->query_id) {
$this->result = mysql_fetch_row($this->query_id);
return $this->result;
}
}
public function fetch_object () {
if ($this->query_id) {
$this->result = mysql_fetch_object($this->query_id);
return $this->result;
}
}
// 獲取 num_rows
public function num_rows () {
if ($this->query_id) {
$this->num_rows = mysql_num_rows($this->query_id);
return $this->num_rows;
}
}
// 獲取 insert_id
public function insert_id () {
return $this->insert_id = mysql_insert_id();
}
// 顯示共有多少?gòu)埍?
public function show_tables () {
$this->query("show tables");
if ($this->query_id) {
echo "數(shù)據(jù)庫(kù) $this->db_name 共有 ".$this->num_rows($this->query_id)." 張表<br/>";
$i = 1;
while ($row = $this->fetch_array($this->query_id)){
echo "$i -- $row[0]<br/>";
$i ++;
}
}
}
// 顯示共有多少個(gè)數(shù)據(jù)庫(kù)
public function show_dbs(){
$this->query("show databases");
if ($this->query_id) {
echo "共有數(shù)據(jù)庫(kù) ".$this->num_rows($this->query_id)." 個(gè)<br/>";
$i = 1;
while ($this->row = $this->fetch_array($this->query_id)){
echo "$i -- ".$this->row[Database]."<br />";
$i ++;
}
}
}
// 刪除數(shù)據(jù)庫(kù):返回刪除結(jié)果
public function drop_db ($db_name='') {
if ($db_name == '') {
$db_name = $this->db_name;//默認(rèn)刪除當(dāng)前數(shù)據(jù)庫(kù)
$this->query("DROP DATABASE $db_name");
}else {
$this->query("DROP DATABASE $db_name");
}
if ($this->query_id) {
return "數(shù)據(jù)庫(kù) $db_name 刪除成功";
}else {
$this->show_error("數(shù)據(jù)庫(kù) $db_name 刪除失敗");
}
}
// 刪除數(shù)據(jù)表:返回刪除結(jié)果
public function drop_table ($table_name) {
$this->query("DROP TABLE $table_name");
if ($this->query_id) {
return "數(shù)據(jù)表 $table_name 刪除成功";
}else {
$this->show_error("數(shù)據(jù)表 $table_name 刪除失敗");
}
}
// 創(chuàng)建數(shù)據(jù)庫(kù)
public function create_db ($db_name) {
$this->query("CREATE DATABASE $db_name");
if($this->query_id){
return "數(shù)據(jù)庫(kù) $db_name 創(chuàng)建成功";
}else {
$this->show_error("數(shù)據(jù)庫(kù) $db_name 創(chuàng)建失敗");
}
}
// 獲取數(shù)據(jù)庫(kù)版本
public function get_info(){
echo mysql_get_server_info();
}
// 釋放內(nèi)存
public function free_result () {
if ( @mysql_free_result($this->query_id) )
unset ($this->result);
$this->query_id = 0;
}
} // End class
?>

相關(guān)文章

  • PHP手機(jī)號(hào)碼及郵箱正則表達(dá)式實(shí)例解析

    PHP手機(jī)號(hào)碼及郵箱正則表達(dá)式實(shí)例解析

    這篇文章主要介紹了PHP手機(jī)號(hào)碼及郵箱正則表達(dá)式實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • php實(shí)現(xiàn)保存submit內(nèi)容之后禁止刷新

    php實(shí)現(xiàn)保存submit內(nèi)容之后禁止刷新

    這篇文章主要介紹了php保存submit內(nèi)容之后禁止刷新的具體實(shí)現(xiàn),需要的朋友可以參考下
    2014-03-03
  • 帝國(guó)cms目錄結(jié)構(gòu)分享

    帝國(guó)cms目錄結(jié)構(gòu)分享

    本文給大家分享的是一款非常不錯(cuò)的也很實(shí)用的php的內(nèi)容發(fā)布系統(tǒng)--帝國(guó)CMS的目錄結(jié)構(gòu),方便大家進(jìn)行二次開發(fā)。
    2015-07-07
  • PHP Memcached應(yīng)用實(shí)現(xiàn)代碼

    PHP Memcached應(yīng)用實(shí)現(xiàn)代碼

    在很多場(chǎng)合,我們都會(huì)聽到 memcached 這個(gè)名字,但很多同學(xué)只是聽過,并沒有用過或?qū)嶋H了解過,只知道它是一個(gè)很不錯(cuò)的東東。這里簡(jiǎn)單介紹一下,memcached 是高效、快速的分布式內(nèi)存對(duì)象緩存系統(tǒng),主要用于加速 WEB 動(dòng)態(tài)應(yīng)用程序。
    2010-02-02
  • PHP設(shè)計(jì)模式之迭代器模式淺析

    PHP設(shè)計(jì)模式之迭代器模式淺析

    迭代器(Iterator)模式,它在一個(gè)很常見的過程上提供了一個(gè)抽象:位于對(duì)象圖不明部分的一組對(duì)象(或標(biāo)量)集合上的迭代。迭代有幾種不同的具體執(zhí)行方法:在數(shù)組屬性,集合對(duì)象,數(shù)組,甚至一個(gè)查詢結(jié)果集之上迭代
    2023-04-04
  • PHP中::、-&gt;、self、$this幾種操作符的區(qū)別介紹

    PHP中::、-&gt;、self、$this幾種操作符的區(qū)別介紹

    這篇文章主要介紹PHP中幾種比較常用的操作符的區(qū)別,特分享下,方便需要的朋友
    2013-04-04
  • php中try catch捕獲異常實(shí)例詳解

    php中try catch捕獲異常實(shí)例詳解

    這篇文章主要介紹了php中try catch捕獲異常實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • 索引的優(yōu)點(diǎn)和缺點(diǎn)

    索引的優(yōu)點(diǎn)和缺點(diǎn)

    索引的優(yōu)點(diǎn)和缺點(diǎn)...
    2006-11-11
  • 解析CodeIgniter自定義配置文件

    解析CodeIgniter自定義配置文件

    本篇文章是對(duì)CodeIgniter自定義配置文件進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • PHP-FPM的配置與優(yōu)化講解

    PHP-FPM的配置與優(yōu)化講解

    今天小編就為大家分享一篇關(guān)于PHP-FPM的配置與優(yōu)化講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03

最新評(píng)論

清新县| 卢湾区| 安义县| 惠东县| 安义县| 东乡县| 铜陵市| 旌德县| 湛江市| 临朐县| 新巴尔虎右旗| 台江县| 香格里拉县| 商城县| 黄浦区| 尉犁县| 神木县| 湟源县| 乌恰县| 增城市| 陕西省| 曲松县| 富蕴县| 罗甸县| 尚义县| 马鞍山市| 海丰县| 郯城县| 苗栗市| 天等县| 昭苏县| 滁州市| 三门峡市| 新蔡县| 临夏县| 措美县| 宣汉县| 甘洛县| 美姑县| 利川市| 平江县|