本页主题: MySQL数据库操作封装 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

jacking

该用户目前不在线
级别: 论坛版主
精华: 2
发帖: 294
威望: 299 点
金钱: 2980 RMB
贡献值: 0 点
注册时间:2007-05-17
最后登录:2008-08-07

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
();
?>




顶端 Posted: 2008-01-03 18:55 | [楼 主]
thetokin

该用户目前不在线
级别: 禁止发言
精华: 0
发帖: 12
威望: 13 点
金钱: 120 RMB
贡献值: 0 点
注册时间:2008-05-31
最后登录:2008-07-12

笑话

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.
顶端 Posted: 2008-06-16 03:28 | 1 楼
开源嘛论坛 » linux、mysql、apache探讨

Guest cache page, Update at 2008-12-04 07:03 桂ICP备07006725号
Powered by PHPWind v6.0 Certificate Code © 2003-07 PHPWind.com Corporation