Пример #1
0
 /**
  * @param string $dbini  在 config/db.ini.php中配置数据库连接
  */
 function __construct($dbini)
 {
     $this->_dbConfig = SDb::getConfig($dbini);
     $this->_db = SDb::getDbEngine("pdo_mysql");
     $this->_db->init($this->_dbConfig);
     $this->_time = time();
 }
Пример #2
0
 /**
  * 释放所有对象和数据库连接
  * return object|false
  */
 public static function destroy()
 {
     // 清除数据库连接,防止长连接导致的数据库超时
     $db = SDb::getDbEngine("pdo_new_mysql");
     $db->disconnect();
     // 释放所有数据库对象
     self::clear();
 }
Пример #3
0
 function __construct($pkid = false)
 {
     $this->_dbConfig = SDb::getConfig("default");
     $this->_db = SDb::getDbEngine("pdo_mysql");
     $this->_db->init($this->_dbConfig);
     $this->_time = time();
     if ($pkid !== false) {
         $this->setPkid($pkid);
     }
 }
Пример #4
0
<?php

/*
drop table if exists test;
CREATE TABLE `test` (
  `id` int not null primary key auto_increment,
  `name` varchar(30) default NULL,
  `password` varchar(30) default NULL,
  KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
*/
$db = SDb::getDbEngine("mysql");
$db = SDb::getDbEngine("pdo_mysql");
if (!$db) {
    die("DbEngine not exits");
}
$db->init(array("host" => "localhost", "user" => "root", "password" => "", "database" => "test"));
//插入记录
print_r($db->insert($table = "test", $items = array("name" => "testName", "password" => "testPassword")));
//检索一个
print_r($db->selectOne($table = "test", $condition = array(), $items = array("name")));
//按条件检索一个
print_r($db->selectOne($table = "test", $condition = array("id" => 1), $items = array("*")));
//搜索全部
$db->setLimit(-1);
print_r($db->select($table = "test", $condition = array(), $items = array("*")));
//按页检索
$db->setPage(2);
$db->setLimit(5);
//是否算总数
$db->setCount(true);