点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 企业应用>> 新翔网络OA系统V1.0>> 源文件浏览
[商业版 200RMB] WebForm,下载次数:1 次 | 关键字: PHP MYSQL OA 办公 网络办公

源码截图

源码目录树

;
当前路径:db.php
<?php
/**
 * PDO类的封装,使用更方便,方法名称同微擎,不过需要类调用,在微擎内提取出来的
$db = new Pdo('localhost','root','111','3306','tp','oauth_');
var_dump($db->get('users'));
$db->debug();//显示调试语句
 * date 2018.5.21
 * author yoby
 */

class Db{
    protected $host;
    protected $username;
    protected  $password;
    protected  $post;
    protected $database;
    protected $tablepre;
    protected $db;
    protected  $errors=array();

   public function __construct($host='localhost',$username='',$password='',$post='3306',$database='',$tablepre='db_')
    {
        $this->host = $host;
        $this->username = $username;
        $this->password = $password;
        $this->post = $post;
        $this->database = $database;
        $this->tablepre=$tablepre;
        $this->db = new PDO("mysql:dbname={$database};host={$host};port={$post};charset=utf8", $username, $password);
        $sql = "SET NAMES 'utf8';";
        $this->db->exec($sql);
        $this->db->exec("SET sql_mode='';");
    }

    /**
     * 返回带前缀表名
     * @param $table 表名
     * @return string
     */
    public function tablename($table){
        return $this->tablepre .$table;
    }

    /**
     * 支持写操作的更新删除,不能查询
     * @param $sql
     * @param array $params
     * @return bool|int
     */
    public function query($sql, $params = array()) {
        $sqlsafe = SqlPaser::checkquery($sql);

        if (empty($params)) {
            $result = $this->db->exec($sql);
            $this->logging($sql, array(), $this->db->errorInfo());
            return $result;
        }
        $statement = $this->prepare($sql);
        $result = $statement->execute($params);

        $this->logging($sql, $params, $statement->errorInfo());


        if (!$result) {
            return false;
        } else {
            return $statement->rowCount();
        }
    }

    /**
     * 查询一条数据
     * @param $sql
     * @param array $params
     * @return bool|mixed
     */
    public function fetch($sql, $params = array()) {

        $statement = $this->prepare($sql);
        $result = $statement->execute($params);

        $this->logging($sql, $params, $statement->errorInfo());

        if (!$result) {
            return false;
        } else {
            $data = $statement->fetch(PDO::FETCH_ASSOC);
            return $data;
        }
    }

    /**
     * 查询多条数据
     * @param $sql
     * @param array $params
     * @param string $keyfield
     * @return array|bool
     */
    public function fetchall($sql, $params = array(), $keyfield = '') {

        $statement = $this->prepare($sql);
        $result = $statement->execute($params);

        $this->logging($sql, $params, $statement->errorInfo());

        if (!$result) {
            return false;
        } else {
            if (empty($keyfield)) {
                $result = $statement->fetchAll(pdo::FETCH_ASSOC);
            } else {
                $temp = $statement->fetchAll(pdo::FETCH_ASSOC);
                $result = array();
                if (!empty($temp)) {
                    foreach ($temp as $key => &$row) {
                        if (isset($row[$keyfield])) {
                            $result[$row[$keyfield]] = $row;
                        } else {
                            $result[] = $row;
                        }
                    }
                }
            }
            return $result;
        }
    }
    /*
     * 返回数据第一条第N列
     */
    public function fetchcolumn($sql, $params = array(), $column = 0) {

        $statement = $this->prepare($sql);
        $result = $statement->execute($params);

        $this->logging($sql, $params, $statement->errorInfo());

        if (!$result) {
            return false;
        } else {
            $data = $statement->fetchColumn($column);
            return $data;
        }
    }

    /**
     * 查询一条记录,比fetch简单
     * @param $tablename表名不带前缀
     * @param array $params 查询数组
     * @param array $fields 要返回字段数组
     * @param array $orderby 排序字段数组
     * @return bool|mixed
     */
    public function get($tablename, $params = array(), $fields = array(), $orderby = array()) {
        $select = SqlPaser::parseSelect($fields);
        $condition = SqlPaser::parseParameter($params, 'AND');
        $orderbysql = SqlPaser::parseOrderby($orderby);

        $sql = "{$select} FROM " . $this->tablename($tablename) . (!empty($condition['fields']) ? " WHERE {$condition['fields']}" : '') . " $orderbysql LIMIT 1";
        return $this->fetch($sql, $condition['params']);
    }

    /**
     * 查询多条数据
     * @param $tablename 不含前缀表明
     * @param array $params 查询条件
     * @param array $fields
     * @param string $keyfield
     * @param array $orderby 排序
     * @param array $limit 限制条数
     * @return array|bool
     */
    public function getall($tablename, $params = array(), $fields = array(), $keyfield = '', $orderby = array(), $limit = array()) {
        $select = SqlPaser::parseSelect($fields);
        $condition = SqlPaser::parseParameter($params, 'AND');

        $limitsql = SqlPaser::parseLimit($limit);
        $orderbysql = SqlPaser::...
完整源码文件,请先购买后再查看
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号