jacking
级别: 论坛版主
UID: 2
精华: 2
发帖: 295
威望: 309 点
金钱: 2990 RMB
贡献值: 0 点
注册时间:2007-05-17
最后登录:2008-12-31
楼主  发表于: 2008-01-03 18:55

 MySQL数据库操作封装


转贴:逆雪寒 这个就是 db.inc.php 文件.主要的数据库操作都在里面了.更多的操作功能封装以后慢慢写了
========================================================================

<?php
/*
逆雪寒版权.哈哈哈哈哈哈哈哈哈哈
*/
   
class dbso
{
       
        function
connect($dbhost,$dbuser,$dbpwd,$dbname,$dbcharset
) {
            (
$yhmlink = @mysql_connect($dbhost,$dbuser,$dbpwd)) && ($yhmlink=@mysql_pconnect($dbhost,$dbuser,$dbpwd
));
            if(!
$yhmlink
) {
                echo(
'no connect dbbase'
);
            }
           
$this->query("SET NAMES $dbcharset"
);
           
mysql_select_db($dbname,$yhmlink
);       
      }
     
      function
query($sql,$type=''
) {
          return
function_exists('mysql_unbuffered_query')&& $type=='unbuff' ? $query = mysql_unbuffered_query($sql) : $query = mysql_query($sql
);
      }
     
        function
fetch_array($query
) {
            return
mysql_fetch_array($query,MYSQL_ASSOC
);       
        }
       
        function
result($query,$row
) {
            return
mysql_result($query,$row
);   
        }
       
        function
num_row($query
) {
            return   
mysql_num_rows($query
);
        }
       
        function
free_result($query
) {
            return
mysql_free_result($query
);   
        }
       
        function
affected_row
() {
            return
mysql_affected_rows
();   
        }
       
        function
insert_id
() {
            return
mysql_insert_id
();   
        }
       
        function
version
() {
            return
substr(mysql_get_server_info(),0,strpos(mysql_get_server_info(),'-'
));   
        }
       
        function
close($link
) {
            return
mysql_close($link
);   
        }
    }
   
?>


这个就是 全局文件. 我自己命名为common.inc.php
复制PHP内容到剪贴板 PHP代码:

<?php

   
require_once 'db.inc.php'
;
   
   
$dbcfg
= array(
       
'server' => 'localhost'
,
       
'dbuser' => 'root'
,
       
'dbpwd'  => '1'
,
       
'dbname' => 'dz5'
,
       
'dbcharset' =>
'utf8'
   
);

   
$db = &new dbso
;
   
$db->connect($dbcfg['server'],$dbcfg['dbuser'],$dbcfg['dbpwd'],$dbcfg['dbname'],$dbcfg['dbcharset'
]);
?>
PHP代码:

<?php
   
include_once './include/common.inc.php'
;
    echo
$db->version
();
?>




thetokin
级别: 新手上路
UID: 2866
精华: 0
发帖: 12
威望: 13 点
金钱: 120 RMB
贡献值: 0 点
注册时间:2008-05-31
最后登录:2008-07-12
1楼  发表于: 2008-06-16 03:28

 笑话

When the order finished wow gold  completely, we will send all wow gold cheap information to you, including the email by signing. We promise the [url=www.gold-aoc.com]aoc gold[/url] will be safe, we will never use it again.
Thanks for your age of conan gold and enjoy the TOP Package. If you have any other question, please contact our live help any time aoc power leveling.