search
Homephp教程PHP源码实例数据库连接类

<script>ec(2);</script>

require_once("Config.inc.php");//系统配置文件

    
/*
    $DBHOST="localhost"; //主机名
    $DBUSER="root"; // 数据库用户名
    $DBPWD=""; //密码
    $DBNAME="test" ; //数据库名
    */

    
//定义数据库类

    class DataBase
    {
        
//定义属性

        var $mConnId;        
//连接标识        

        var $mSqlString;
//待执行的SQL语句

        var $mResultArray;    
//执行Select语句返回的结果数组        

        
        
//__construct(),构造函数,建立数据库的连接

        function __construct($pHost,$pUser,$pPwd,$pDbName){            
            $this->mConnId=mysql_connect ($pHost,$pUser,$pPwd);
//建立连接

            mysql_select_db($pDbName, $this->mConnId);    
//选择数据库

            mysql_query("set names 'gbk'");
//设置数据库编码为GBK

        }
        
        
//__destruct:析构函数,断开连接

        function __destruct(){
            mysql_close($this->mConnId);
//此处还有问题......

        }
        
        
//执行SQL语句

        function ExecuteSql(){
            mysql_query($this->mSqlString);
        }
        
        
//查询数据,返回值为对象数组,数组中的每一元素为一行记录构成的对象

        function Query(){
            $i=0;
            $query_result=mysql_query($this->mSqlString,$this->mConnId);
            while($row=mysql_fetch_object($query_result)){
                $this->mResultArray[$i++]=$row;
            }
        }
    
    }
//class DataBase


    
//以下为测试用

    $db=new DataBase($DBHOST,$DBUSER,$DBPWD,$DBNAME);
    $db->mSqlString="update student set phone='123' where id='04261001' ";
    $db->ExecuteSql();
    $db->mSqlString="select * from student where id='04261001' ";
    $db->Query();
    print_r($db->mResultArray);
//输出测试结果

    

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function