> php教程 > php手册 > php操作mysql的类!

php操作mysql的类!

WBOY
풀어 주다: 2016-06-21 08:58:15
원래의
827명이 탐색했습니다.

mysql


# All text and code within this file are (c)opyright
# Pangolin Software Limited 2000.
#
# You may edit this file to customise it for your web-site,
# however, the actual source code may not be altered in
# any way without the prior written permission of Pangolin
# Software Limited.
# This file is part of the Pangolin Vote distribution.
# Contact: pangolin@pango.co.uk or www.pango.co.uk for more info.
/*
* Utility routines for MySQL.
* Modified from code from: http://www.webwizard.com/tutorials/mysql/
*/
class MySQL_class {
    # Make sure you fill in the values below for your web-site.
    # They are for user,password,host and database respectively.
    #
    var $user = "USERNAME";
    var $pass = "PASSWORD";
    var $thedatabase ="DATABASE";
    var $host = "localhost";

    var $db, $id, $result, $rows, $data, $a_rows;
    /*
     * It's a minor security hole to have the username and password
     * appear here.  Generally there isn't any way of getting around it
     * if you're using a commercial web hosting service.  There are other
     * ways if it's your own web server.
     */
    function Setup ($user, $pass) {
        $this->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("    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";
}
?>



관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿