<?php defined('ACC')||exit('Access Denied'); // 封装mysql操作类,包括连接功能,及查询功能. class mysql extends absdb{ protected static $ins = null; protected $host; // 主机名 protected $user; // 用户名 protected $passwd; // 密码 protected $db; // 数据库名 protected $port; // 端口 protected $conn = null; // 在内部操作,获得一个对象 public static function getIns() { if(self::$ins === null) { self::$ins = new self(); } $conf = conf::getIns(); self::$ins->host = $conf->host; self::$ins->user = $conf->user; self::$ins->passwd = $conf->pwd; self::$ins->db = $conf->db; self::$ins->port = $conf->port; self::$ins->connect(); self::$ins->select_db(); self::$ins->setChar(); return self::$ins; } // 不让外部做new操作, protected function __construct() { } // 连接数据库 public function connect() { $this->conn = @mysql_connect($this->host,$this->user,$this->passwd,$this->port); if(!$this->conn) { $error = new Exception('数据库连不上',9); throw $error; } } // 发送sql查询 public function query($sql) { $rs = mysql_query($sql,$this->conn); if(!$rs) { log::write($sql); } return $rs; }
This is a PHP class that implements mysql in singleton mode. Friends who need it can download it and use it.
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article
06Jul2016
A simple implementation method of PHP singleton mode, PHP instance mode. Simple implementation method of php singleton mode, php example mode Simple implementation method of php singleton mode php /** * Singleton mode of design mode * $_instance must be declared as a static private variable * Construction
12Jul2016
A simple implementation method of PHP singleton mode, PHP instance mode. Simple implementation method of php singleton mode, php example mode Simple implementation method of php singleton mode php /** * Singleton mode of design mode * $_instance must be declared as a static private variable * Construction
![How Do I Link Static Libraries That Depend on Other Static Libraries?](https://img.php.cn/upload/article/001/246/273/173408941480807.jpg)
13Dec2024
Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...
12Jul2016
PHP implements a complete instance of the Model base class based on mysqli, phpmysqlimodel base. PHP implements a complete example of the Model base class based on mysqli, phpmysqlimodel base This article describes an example of PHP implementing the Model base class based on mysqli. Share it with everyone for your reference, the details are as follows: DB.c
12Jul2016
PHP implements the generation of complete instances of MYSQL statement classes and mysql statements through parameters. A complete example of generating a MYSQL statement class through parameters in PHP, mysql statement. This example describes how to generate a MYSQL statement class through parameters in PHP. Share it with everyone for your reference, the details are as follows
![How to Silence TensorFlow\'s Debugging Output?](https://img.php.cn/upload/article/001/246/273/173013069196898.jpg)
28Oct2024
Suppression of Tensorflow Debugging OutputTensorflow prints extensive information about loaded libraries, found devices, and other debugging data...
![](/static/imghwm/down_right.png)
![](/static/imghwm/taglogo.png)
Hot Tools
![PHP library for dependency injection containers](https://img.php.cn/upload/manual/000/000/001/5e21721e79a2b232.png)
PHP library for dependency injection containers
PHP library for dependency injection containers
A collection of 50 excellent classic PHP algorithms
Classic PHP algorithm, learn excellent ideas and expand your thinking
Small PHP library for optimizing images
Small PHP library for optimizing images
![](/static/imghwm/taglogo.png)