一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

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

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
?>

php技術Mysql數據庫操作類( 1127版,提供源碼下載 ),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: www.色.con| 国内精品免费麻豆网站91麻豆 | 最新亚洲情黄在线网站 | 亚洲资源在线 | 在线看国产视频 | 精品久久久中文字幕一区 | 午夜免费的国产片在线观看 | 久久九九国产精品怡红院 | 婷婷伊人久久 | 欧美日韩亚洲国产千人斩 | 中文字幕第一区 | 日韩在线 中文字幕 | 四虎网址 | a亚洲va韩国va欧美va久久 | 国产精品亚洲欧美一区麻豆 | 亚洲国产欧美在线成人aaaa | 奇米影视久久777中文字幕 | 一级黄色a毛片 | 91精品国产91久久久久 | www.日本高清视频 | 一道精品视频一区二区三区男同 | 日本一区二区免费看 | 91精品全国免费观看含羞草 | 大量国产激情视频在线观看 | 一区在线视频 | 目韩一区二区三区系列片丶 | 精品综合在线 | 国产福利毛片 | 色噜噜视频 | 日韩永久免费进入2015 | 好吊色青青青国产欧美日韩 | 热久久99影院 | 深夜影院深a| 久久99亚洲综合精品首页 | 国产91精品一区二区麻豆网站 | 一区二区三区视频在线 | 亚洲天堂久久 | seyoyo在线 | 日韩午夜在线视频 | 亚洲最大色网站 | 亚洲激情五月 |