资源大全 | 神秘文化 | 在线翻译 | QQ专区 | 视频教程 | 彩信频道 | 搜索引擎 | BT下载 |  | 网站地图
设为首页
加入收藏
联系站长
您现在的位置: 一百网络 >> PHP编程 >> 数据库相关 >> 文档正文
最近更新
普通文档 给大家一个php+oracle的
普通文档 大家在碰到这样的情况下
普通文档 使用MySQL时的一些常见错
推荐文档 自己动手做一个SQL解释器
普通文档 最小化数据传输——在客
普通文档 谈谈数据从sql server数
普通文档 一个php处理oracle的 lo
普通文档 Tutorial for migrating
普通文档 好了,我经过大家的支持
普通文档 写了一个odbc连mssql分页
推荐文章
推荐文档 自己动手做一个SQL解释器
推荐文档 MySQL服务器的启动与停止
推荐文档 MySQL用户管理(转)
推荐文档 php操作mysql的类!
推荐文档 PHP4连接Oracle 8i的方法
推荐文档 如何实现MySQL中的用户管
推荐文档 PHPLIB 和多个数据库连接
推荐文档 PHP+Oracle(OCI)初步
推荐文档 数据库设计技巧(一)
推荐文档 SQL语言快速入门(一)
推荐文档 MySQL索引分析和优化
推荐文档 数据库设计范式
推荐文档 PHP调用三种数据库的方法
推荐文档 PHP如何透过ODBC来存取数
推荐文档 自己写的mysql类
php操作mysql的类!

文章作者:佚名 录入时间:2006-6-9 来源:不详
网站声明:本站的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出处和原始作者,文章版权归本网站与文章作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。


<?
# 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("<p>Unable to continue.<p>");
            }
        $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 ("<p>Unable to continue.<p>");
        }
    }
    # 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("</ul></dl></ol<\n");
    echo("</table></script>\n");
    # Display the error message
    $text  = "<font color=\"#ff0000\"><p><b>Error: $msg :";
    $text .= mysql_error();
    $text .= "</b></font>\n";
    $errormsg=$text;
    # get rid of Unable to fetch error messages
    if (strpos($errormsg,"Unable to fetch")==false)
    print "$errormsg\n";
}
?>

  • 上一篇文档:

  • 下一篇文档:
  •     查找更多“php操作mysql的类!”的内容  
    相关连接
  • PHP实现文件安全下载-PHP教程,文件处理

  • 好东西和大家分享~同时上传100个文件上传的程序~(代码)文件一:fileup.pl-PHP教程,文件

  • 好东西和大家分享~同时上传100个文件上传的程序~(代码)文件三:fileup.php-PHP教程,文

  • 好东西和大家分享~同时上传100个文件上传的程序~(代码)文件二:fileup.plphpfileup.ht

  • 如何使用PHP操作文件(文件读取篇)-PHP教程,文件处理