static function findAll($condition) { //Выборка записей; $table = static::getTable(); $sql = "Select * from " . $table; if ($condition) { $sql .= " {$condition}"; } return Db::getInstance()->query($sql, \PDO::FETCH_ASSOC); }
public function __construct($select = false) { $config = (require $this->config); $this->configure($config); $this->db = Db::getInstance()->connect($this); $modelName = get_class($this); $arrExp = explode('\\', $modelName); $tableName = strtolower($arrExp[1]); $this->table = $tableName; $sql = $this->_getSelect($select); if ($sql) { $this->_getResult("SELECT * FROM {$this->table}" . $sql); } }
public function __construct() { $this->conn = \Core\Db::getInstance(); }
<?php session_start(); require_once "Core/App.php"; use Core\Db; use Config\DbConfig; use Core\App; spl_autoload_register(function ($class) { $classPath = str_replace('\\', '/', $class); require_once $classPath . '.php'; }); Db::SetInstance(DbConfig::DB_INSTANCE, DbConfig::DB_DRIVER, DbConfig::DB_USER, DbConfig::DB_PASS, DbConfig::DB_NAME, DbConfig::DB_HOST); $app = new App(Db::getInstance(DbConfig::DB_INSTANCE)); function loadTemplate($templateName, $data = null) { require_once 'Templates/' . $templateName . '.php'; }
/** * 切换当前的数据库连接 * @access public * @param integer $linkNum 连接序号 * @param mixed $config 数据库连接信息 * @param boolean $force 强制重新连接 * @return Model */ public function db($linkNum = '', $config = '', $force = false) { if ('' === $linkNum && $this->db) { return $this->db; } if (!isset($this->_db[$linkNum]) || $force) { // 创建一个新的实例 if (!empty($config) && is_string($config) && false === strpos($config, '/')) { // 支持读取配置参数 $config = Config::get($config); } $this->_db[$linkNum] = \Core\Db::getInstance($config); } elseif (NULL === $config) { $this->_db[$linkNum]->close(); // 关闭数据库连接 unset($this->_db[$linkNum]); return; } // 切换数据库连接 $this->db = $this->_db[$linkNum]; $this->_after_db(); // 字段检测 if (!empty($this->name) && $this->autoCheckFields) { $this->_checkTableInfo(); } return $this; }