php封装连接MySql类
Mysql.class.php
<?php
class mysql
{
private $mysqli;
private $result;
private $sql;
public function connect()
{
$host = "localhost";
//主机地址
$username = "root";
//用户名
$password = "root";
//密码
$database = "onedata";
//数据库
$port = "3306";
//端口号
$this->mysqli = new mysqli($host, $username, $password, $database, $port);
if ($this->mysqli->connect_errno) {
exit("连接失败" . $this->mysqli->connect_errno);
}
}
//数据查询-返回条数
public function select($table, $field = Null, $link = Null, $where = Null, $sort = Null, $paging = Null)
{
$this->sql = "SELECT * FROM {
$table} ";
if (!empty($field)) {
// $field = '`' . implode('`,`', $field) . '`';
$this->sql = str_replace('*', $field, $this->sql);
}
if (!empty