免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 985 | 回复: 0
打印 上一主题 下一主题

php操作mysql类 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-17 16:09 |只看该作者 |倒序浏览
user = $user;
        $this->pass = $pass;
    }
    function Create () {
        $db=$this->thedatabase;
        $this->db = $db;
        $crash=0;
        $this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or
        $crash=1;
        if ($crash==1) {
            MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host - Either your username, password or database values are incorrect in vutil.php3 or you have not started MYSQL on your web server!");
            die("Unable to continue.");
            }
        $this->selectdb($db);
    }
    function SelectDB ($db) {
        $crash=0;
        @mysql_select_db($db, $this->id) or $crash=1;
        if ($crash==1)
        {
        MySQL_ErrorMsg ("Unable to select database: $db : The value in vutil.php3 may be incorrect.");
        die ("Unable to continue.");
        }
    }
    # Use this function is the query will return multiple rows.  Use the Fetch
    # routine to loop through those rows.
    function Query ($query) {
        $this->result = @mysql_query($query, $this->id) or
            MySQL_ErrorMsg ("Unable to perform query: $query");
        $this->rows = @mysql_num_rows($this->result);
        $this->a_rows = @mysql_affected_rows($this->result);
    }
    # Use this function if the query will only return a
    # single data element.
    function QueryItem ($query) {
        $this->result = @mysql_query($query, $this->id) or
            MySQL_ErrorMsg ("Unable to perform query: $query");
        $this->rows = @mysql_num_rows($this->result);
        $this->a_rows = @mysql_affected_rows($this->result);
        $this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch.");
        return($this->data[0]);
    }
    # This function is useful if the query will only return a
    # single row.
    function QueryRow ($query) {
        $this->result = @mysql_query($query, $this->id) or
            MySQL_ErrorMsg ("Unable to perform query: $query");
        $this->rows = @mysql_num_rows($this->result);
        $this->a_rows = @mysql_affected_rows($this->result);
        $this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch.");
        return($this->data);
    }
    function Fetch ($row) {
        @mysql_data_seek($this->result, $row) or MySQL_ErrorMsg ("Unable to seek data.");
        $this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch.");
    }
    function Insert ($query) {
        $this->result = @mysql_query($query, $this->id) or
            MySQL_ErrorMsg ("Unable to perform insert: $query");
        $this->a_rows = @mysql_affected_rows($this->result);
    }
    function Update ($query) {
        $this->result = @mysql_query($query, $this->id) or
            MySQL_ErrorMsg ("Unable to perform update: $query");
        $this->a_rows = @mysql_affected_rows($this->result);
    }
    function Delete ($query) {
        $this->result = @mysql_query($query, $this->id) or
            MySQL_ErrorMsg ("Unable to perform Delete: $query");
        $this->a_rows = @mysql_affected_rows($this->result);
    }
}
/* ********************************************************************
* MySQL_ErrorMsg
*
* Print out an MySQL error message
*
*/
function MySQL_ErrorMsg ($msg) {
    # Close out a bunch of HTML constructs which might prevent
    # the HTML page from displaying the error text.
    echo("\n");
    # Display the error message
    $text  = "Error: $msg :";
    $text .= mysql_error();
    $text .= "\n";
    $errormsg=$text;
    # get rid of Unable to fetch error messages
    if (strpos($errormsg,"Unable to fetch")==false)
    print "$errormsg\n";
}
?>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8454/showart_68547.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP