PHP实现的一个简单的数据库操作类
PHP实现的一个简单的数据库操作类
实现的功能:
- 在实例化的时候能设置连接字符集
- 在实例化的时候能连接数据库
- 在实例化的时候能选择默认数据库
- 销毁对象时关闭数据库
代码如下:
<code class="language-php hljs "><?php // 数据库操作类MySQLDB class MySQLDB { // 声明属性 private $server; private $username; private $password; public $default_db; public $link; // 声明构造函数 public function __construct($server,$username,$password,$default_db) { // 设置连接字符串 $this->server = $server; $this->username = $username; $this->password = $password; $this->default_db = $default_db; // 连接数据库 $this->link = mysql_connect($this->server,$this->username,$this->password); if (!$this->link) { echo 'database connect failure!'; } // 设置默认的数据库 $bool = mysql_select_db($this->default_db,$this->link); if (!$bool) { echo 'Select default_db failure!'; } } // 声明析构函数 public function __destruct() { mysql_close($this->link); } }</code>
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
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Seashell Riddle Solution
2 weeks agoByDDD
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

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.