一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - Mysql數據庫操作類( 1127版,提供源碼下載 )

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

2019-11-12 14:12php教程網 PHP教程

Mysql數據庫操作類,學習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;//調試開關,默認關閉 
private $query_id; //用于判斷sql語句是否執行成功 
private $result; //結果集 
private $num_rows; //結果集中行的數目,僅對select有效 
private $insert_id; //上一步 INSERT 操作產生的 ID 
// 構造/析構函數 
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); 

// 連接/選擇數據庫 
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('數據庫-連接失敗:用戶名或密碼錯誤!'); 

if (!@mysql_select_db($this->db_name,$this->conn)) { 
$this->show_error("數據庫-選擇失敗:數據庫 $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> 執行時遇到錯誤"); 
return $this->query_id; 

// 顯示詳細錯誤信息 
public function show_error ($msg) { 
if($this->debug){ 
$errinfo = mysql_error(); 
echo "錯誤:$msg <br/> 返回:$errinfo<p>"; 
}else{ 
echo '<p>出現錯誤!<p>'; 


// 獲得query執行成功與否的信息 
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 "數據庫 $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 ++; 



// 顯示共有多少個數據庫 
public function show_dbs(){ 
$this->query("show databases"); 
if ($this->query_id) { 
echo "共有數據庫 ".$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 ++; 



// 刪除數據庫:返回刪除結果 
public function drop_db ($db_name='') { 
if ($db_name == '') { 
$db_name = $this->db_name;//默認刪除當前數據庫 
$this->query("DROP DATABASE $db_name"); 
}else { 
$this->query("DROP DATABASE $db_name"); 

if ($this->query_id) { 
return "數據庫 $db_name 刪除成功"; 
}else { 
$this->show_error("數據庫 $db_name 刪除失敗"); 


// 刪除數據表:返回刪除結果 
public function drop_table ($table_name) { 
$this->query("DROP TABLE $table_name"); 
if ($this->query_id) { 
return "數據表 $table_name 刪除成功"; 
}else { 
$this->show_error("數據表 $table_name 刪除失敗"); 


// 創建數據庫 
public function create_db ($db_name) { 
$this->query("CREATE DATABASE $db_name"); 
if($this->query_id){ 
return "數據庫 $db_name 創建成功"; 
}else { 
$this->show_error("數據庫 $db_name 創建失敗"); 


// 獲取數據庫版本 
public function get_info(){ 
echo mysql_get_server_info(); 

// 釋放內存 
public function free_result () { 
if ( @mysql_free_result($this->query_id) ) 
unset ($this->result); 
$this->query_id = 0; 

} // End class 
?> 

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美日韩一区二区三区久久 | 日本免费高清在线 | 91精品国产麻豆国产自产在线 | 亚洲精品在线免费观看视频 | 91精品国产综合久久福利 | 奇米影视中文字幕 | 免费91麻豆精品国产自产在线观看 | 性一交一无一伦一精一品 | sese在线观看 | 午夜久久久久久网站 | 射18p | 黑人巨大精品战中国美女 | 97国产精品久久碰碰牛牛 | 国产成人+亚洲欧洲 | 99精品国产自在现线观看 | 天天成人| 办公室操秘书 | 国产福利在线观看第二区 | 欧美亚洲国产综合在线 | 国内精品91东航翘臀女神在线 | 深夜福利软件 | 给我免费观看的视频在线播放 | 女人把扒开给男人爽的 | 青青青在线视频播放 | 四虎免费看黄 | 日日本老女人 | 香蕉久久久久久狠狠色 | 99这里只有精品在线 | 色偷偷亚洲综合网亚洲 | 亚洲日本中文字幕在线2022 | 无遮挡h肉动漫高清在线 | 国产乱子伦在线观看不卡 | 9总探花新品牛仔背带裤 | 娇喘高潮教室h | 免费xxxxx大片在线观看影视 | 亚洲国产欧美在线人成aaaa20 | 四虎在线最新永久免费 | 精品成人一区二区三区免费视频 | 成年人黄色录像 | 亚洲国产在 | 国产亚洲sss在线观看 |