2021-01-04 PHP面向对象封装MySQL操作函数、文件上传 PHP面向对象封装MySQL操作函数、文件上传 Mysql.class.php<?php class Mysql { public $link; public function __construct() { $this->conn(); } /** * 连接数据库,从配置文件读取配置信息 */ public function conn() { $cfg = require 'config.php'; $this->link = new mysqli($cfg['host'], $cfg['name'], $cfg['password'], $cfg['databaseName'], $cfg['port']); $this->query('set names ' . $cfg['charset']); } /** * 发送query查询 * @param string $sql sql语句 * @return m... 2021年01月04日 1,202 阅读 0 评论
2020-12-02 PHP 封装MySQL操作函数、魔术常量、封装函数 PHP 封装MySQL操作函数、魔术常量、封装函数 mysql.php<?php /** * mysql.php mysql系列操作函数 * @author nianbaibai */ /** * 连接数据库 * * @return resource 连接成功,返回连接数据库的资源 */ function mConn() { static $conn = null; if ($conn === null) { $db = require ROOT . '/lib/config.php'; $conn = mysqli_connect("$db[host]", "$db[name]", "$db[password]", "$db[databaseName]", "$db[port]"); mysqli_query($conn, 'set names ' . $db['charset']); } return $conn; } /... 2020年12月02日 964 阅读 0 评论