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

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

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

<?php
class Mysql {
private $db_host; //主機地址
private $db_user; //用戶名
private $db_pass; //連接密碼
private $db_name; //名稱
private $db_charset; //編碼
private $conn;
public $debug=false;//調(diào)試開關(guān),默認關(guān)閉
private $query_id; //用于判斷sql語句是否執(zhí)行成功
private $result; //結(jié)果集
private $num_rows; //結(jié)果集中行的數(shù)目,僅對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ù)庫
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ù)庫-連接失?。河脩裘蛎艽a錯誤!');
}
if (!@mysql_select_db($this->db_name,$this->conn)) {
$this->show_error("數(shù)據(jù)庫-選擇失?。簲?shù)據(jù)庫 $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í)行時遇到錯誤");
return $this->query_id;
}
// 顯示詳細錯誤信息
public function show_error ($msg) {
if($this->debug){
$errinfo = mysql_error();
echo "錯誤:$msg <br/> 返回:$errinfo<p>";
}else{
echo '<p>出現(xiàn)錯誤!<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();
}
// 顯示共有多少張表
public function show_tables () {
$this->query("show tables");
if ($this->query_id) {
echo "數(shù)據(jù)庫 $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 ++;
}
}
}
// 顯示共有多少個數(shù)據(jù)庫
public function show_dbs(){
$this->query("show databases");
if ($this->query_id) {
echo "共有數(shù)據(jù)庫 ".$this->num_rows($this->query_id)." 個<br/>";
$i = 1;
while ($this->row = $this->fetch_array($this->query_id)){
echo "$i -- ".$this->row[Database]."<br />";
$i ++;
}
}
}
// 刪除數(shù)據(jù)庫:返回刪除結(jié)果
public function drop_db ($db_name='') {
if ($db_name == '') {
$db_name = $this->db_name;//默認刪除當前數(shù)據(jù)庫
$this->query("DROP DATABASE $db_name");
}else {
$this->query("DROP DATABASE $db_name");
}
if ($this->query_id) {
return "數(shù)據(jù)庫 $db_name 刪除成功";
}else {
$this->show_error("數(shù)據(jù)庫 $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ù)庫
public function create_db ($db_name) {
$this->query("CREATE DATABASE $db_name");
if($this->query_id){
return "數(shù)據(jù)庫 $db_name 創(chuàng)建成功";
}else {
$this->show_error("數(shù)據(jù)庫 $db_name 創(chuàng)建失敗");
}
}
// 獲取數(shù)據(jù)庫版本
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手機號碼及郵箱正則表達式實例解析

    PHP手機號碼及郵箱正則表達式實例解析

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

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

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

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

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

    PHP Memcached應用實現(xiàn)代碼

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

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

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

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

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

    php中try catch捕獲異常實例詳解

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

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

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

    解析CodeIgniter自定義配置文件

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

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

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

最新評論

旌德县| 临洮县| 苏尼特左旗| 揭西县| 连平县| 成都市| 广南县| 偏关县| 株洲县| 建湖县| 平谷区| 金川县| 富阳市| 油尖旺区| 崇文区| 齐河县| 白朗县| 吴旗县| 壶关县| 兖州市| 微博| 临沭县| 开平市| 于都县| 蒲江县| 建瓯市| 禹城市| 万荣县| 洱源县| 高州市| 齐齐哈尔市| 耒阳市| 拜泉县| 肇庆市| 梅河口市| 正镶白旗| 积石山| 威海市| 隆林| 舒兰市| 东源县|