function __construct($DBname, $DBip, $DBuser, $DBpwd, $memSwitch = false, $memPort, $memName, $memPath) { $this->DBname = $DBname; $this->DBip = $DBip; $this->DBuser = $DBuser; $this->DBpwd = $DBpwd; $this->memcache_switch = $memSwitch; try { $this->PDO_LINK = new PDO("mysql:host={$this->DBip};dbname={$this->DBname};", $this->DBuser, $this->DBpwd); if ($memSwitch == true) { \RSystem\system::load_class($memName, $memPath, 0); memcacheClass::init($memPort); } $this->PDO_LINK->setAttribute(PDO::ATTR_AUTOCOMMIT, 1); $this->PDO_LINK->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $this->PDO_LINK->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch (PDOException $e) { die("connect fail!" . $e->getMessage()); } $this->PDO_LINK->query('set names utf8'); }
<?php /* * Created by PhpStorm. * 作者:NumberWolf * Email:porschegt23@foxmail.com * APACHE 2.0 LICENSE * Copyright [2016] [Chang Yanlong] * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ \RSystem\system::load_class('db', '', 0); class hello extends db { public $PDO_OBJ = null; public function __construct() { $this->PDO_OBJ = \RSystem\system::load_pdo('', true, 11211); // 当为true时候打开memcache缓存 echo "数据模型实例,已开启缓存"; } public function search() { $ResArr = $this->PDO_OBJ->select_Tab('test')->select_Obj('*')->search_command(); // var_dump($ResArr); return $ResArr; } }