本文整理汇总了PHP中MDB2::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP MDB2::singleton方法的具体用法?PHP MDB2::singleton怎么用?PHP MDB2::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDB2
的用法示例。
在下文中一共展示了MDB2::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LiveUser_Admin_Perm_Container_MDB2_Simple
/**
* Constructor
*
* @access protected
* @param array full liveuser configuration array
* @return void
* @see LiveUser::factory()
*/
function LiveUser_Admin_Perm_Container_MDB2_Simple(&$connectOptions)
{
if (is_array($connectOptions)) {
$function = 'connect';
if (isset($connectOptions['function'])) {
$function = $connectOptions['function'];
unset($connectOptions['function']);
}
foreach ($connectOptions as $key => $value) {
if (isset($this->{$key})) {
$this->{$key} = $value;
}
}
if (isset($connectOptions['connection']) && MDB2::isConnection($connectOptions['connection'])) {
$this->dbc =& $connectOptions['connection'];
$this->init_ok = true;
} elseif (isset($connectOptions['dsn'])) {
$this->dsn = $connectOptions['dsn'];
$options = null;
if (isset($connectOptions['options'])) {
$options = $connectOptions['options'];
}
$options['portability'] = MDB2_PORTABILITY_ALL;
if ($function == 'singleton') {
$this->dbc =& MDB2::singleton($connectOptions['dsn'], $options);
} else {
$this->dbc =& MDB2::connect($connectOptions['dsn'], $options);
}
if (!MDB2::isError($this->dbc)) {
$this->init_ok = true;
}
}
}
}
示例2: __construct
/**
* Create a new instance of a default I2CE table user access mechanism
*/
public function __construct()
{
$protocol = substr(get_class($this), 16);
if (!$protocol) {
$protocol = 'DEFAULT';
}
$this->protocol = $protocol;
$init = I2CE::getUserAccessInit($protocol);
if (empty($init)) {
$options = array();
} else {
$options = json_decode($init, true);
if (!is_array($options)) {
I2CE::raiseError("Invalid user access initilization string");
$options = array();
}
}
if (!array_key_exists('admin_user', $options)) {
$options['admin_user'] = 'i2ce_admin';
}
if (!array_key_exists('admin_pass', $options)) {
$options['admin_pass'] = MDB2::singleton()->dsn['password'];
}
if (!array_key_exists('admin_details', $options) || !is_array($options['admin_details'])) {
$options['admin_details'] = array();
}
if (!array_key_exists('auto_login', $options)) {
$options['auto_login'] = 0;
}
if (!array_key_exists('auto_login_user', $options)) {
$options['auto_login_user'] = false;
}
$this->options = $this->ensureDefaultOptions($options);
}
示例3: R3AppInitDB
function R3AppInitDB()
{
global $mdb2;
global $dsn;
require_once 'MDB2.php';
if (!isset($dsn) || $dsn == '') {
throw new Exception('Missing $dsn');
}
$txtDsn = $dsn['dbtype'] . '://' . $dsn['dbuser'] . ':' . $dsn['dbpass'] . '@' . $dsn['dbhost'] . '/' . $dsn['dbname'];
$db = ezcDbFactory::create($txtDsn);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
PEAR::setErrorHandling(PEAR_ERROR_EXCEPTION);
$mdb2 = MDB2::singleton($txtDsn);
// Needed by user manager and import/export
ezcDbInstance::set($db);
if (isset($dsn['charset'])) {
$db->exec("SET client_encoding TO '{$dsn['charset']}'");
$mdb2->exec("SET client_encoding TO '{$dsn['charset']}'");
}
if (isset($dsn['search_path'])) {
$db->exec("SET search_path TO {$dsn['search_path']}, public");
$mdb2->exec("SET search_path TO {$dsn['search_path']}, public");
}
$db->exec("SET datestyle TO ISO");
$mdb2->exec("SET datestyle TO ISO");
}
示例4: SC_Query
/**
* コンストラクタ.
*
* @param string $dsn データソース名
* @param boolean $force_run エラーが発生しても処理を続行する場合 true
* @param boolean $new 新規に接続を行うかどうか
*/
function SC_Query($dsn = "", $force_run = false, $new = false)
{
if ($dsn == "") {
$dsn = array('phptype' => DB_TYPE, 'username' => DB_USER, 'password' => DB_PASSWORD, 'protocol' => 'tcp', 'hostspec' => DB_SERVER, 'port' => DB_PORT, 'database' => DB_NAME);
}
// Debugモード指定
// 常時ONにするとメモリが解放されない。
// 連続クエリ実行時に問題が生じる。
if (DEBUG_MODE) {
$options['debug'] = PEAR_DB_DEBUG;
} else {
$options['debug'] = 0;
}
// 持続的接続オプション
$options['persistent'] = PEAR_DB_PERSISTENT;
// バッファリング trueにするとメモリが解放されない。
// 連続クエリ実行時に問題が生じる。
$options['result_buffering'] = false;
if ($new) {
$this->conn = MDB2::connect($dsn, $options);
} else {
$this->conn = MDB2::singleton($dsn, $options);
}
if (!PEAR::isError($this->conn)) {
// $this->conn->setCharset("utf8"); XXX SQL Azure では使用できないらしい
$this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC);
}
$this->dbFactory = SC_DB_DBFactory_Ex::getInstance();
$this->force_run = $force_run;
}
示例5: alreadyProcessed
public static function alreadyProcessed($node)
{
if (!is_array($return = self::getNodeHash($node))) {
return null;
}
list($relationship, $hash) = $return;
if (!is_string($relationship) || !is_string($hash)) {
$this->raiseError("Bad parameters");
return null;
}
if (self::$lookup_stmt === null) {
$db = MDB2::singleton();
self::$lookup_stmt = $db->prepare("SELECT id FROM form_relationship_importer WHERE relationship = ? and hash= ?", array('text', 'text'), array('text'), MDB2_PREPARE_RESULT);
if (I2CE::pearError(self::$lookup_stmt, "Could not prepare lookup statement")) {
return null;
}
}
if (!self::$lookup_stmt) {
return null;
}
$results = self::$lookup_stmt->execute(array($relationship, $hash));
$row = $results->fetchRow();
if (!isset($row) || I2CE::pearError($row, "Error getting form id:")) {
return false;
}
return $row->id;
}
示例6: setupDB
/**
* Set up the database and prepared statements if necessary.
*/
protected static function setupDB()
{
if (!self::$db instanceof MDB2_Driver_Common) {
self::$db = MDB2::singleton();
self::$prepared = array();
self::$prepared['user_log'] = self::$db->prepare("SELECT login,logout,activity FROM user_log WHERE user = ? ORDER BY activity DESC LIMIT ?", array('integer', 'integer'), array('date', 'date', 'date'));
if (I2CE::pearError(self::$prepared['user_log'], "Error preparing user_log statement: ")) {
return false;
}
/*
self::$prepared['entry_log'] = self::$db->prepare("SELECT COUNT(DISTINCT e.record) AS records,(SELECT name FROM form WHERE id = (SELECT form FROM record WHERE id = e.record)) AS form,DATE(`date`) AS `date` FROM `entry` e WHERE DATE(`date`) >= (SELECT DISTINCT DATE(`date`) FROM entry WHERE who = ? ORDER BY `date` DESC LIMIT ?,1) AND who = ? GROUP BY 2,3 ORDER BY `date` DESC",
array( 'integer', 'integer', 'integer' ), array( 'integer', 'text', 'date' ) );
if ( I2CE::pearError( self::$prepared['entry_log'], "Error preparing entry_log statement: " ) ) {
return false;
}
self::$prepared['person_log'] = self::$db->prepare("SELECT COUNT(DISTINCT(p.person_id)) AS records,DATE(`date`) AS date FROM entry e,(SELECT r.id,id AS person_id FROM record r WHERE form = ( SELECT id FROM form WHERE name = 'person' ) UNION select r.id,r.parent_id AS person_id from record r where parent_form = 'person' UNION select r.id,p.parent_id AS person_id from record r join record p on p.id = r.parent_id AND p.parent_form = 'person' UNION select r.id,g.parent_id AS person_id from record r join record p on p.id = r.parent_id JOIN record g ON g.id = p.parent_id AND g.parent_form = 'person') AS p WHERE e.who = ? AND e.record = p.id GROUP BY 2 ORDER BY `date` DESC LIMIT ?",
array( 'integer', 'integer' ), array( 'integer', 'date' ) );
if ( I2CE::pearError( self::$prepared['person_log'], "Error preparing person_log statement: " ) ) {
return false;
}
*/
self::$prepared['entry_history'] = self::$db->prepare("SELECT DISTINCT record,DATE(`date`) AS `date` FROM `entry` WHERE `date` >= (SELECT DISTINCT DATE(`date`) FROM entry WHERE who = ? ORDER BY `date` DESC LIMIT ?,1) AND who = ? ORDER BY `date` DESC", array('integer', 'integer', 'integer'), array('integer', 'date'));
if (I2CE::pearError(self::$prepared['entry_history'], "Error preparing entry_history statement: ")) {
return false;
}
}
return true;
}
示例7: connect
public function connect($options = array())
{
$dsn = 'mysql://' . $options['username'] . ':' . $options['password'] . '@' . $options['server'] . '/' . $options['database'];
$this->link = MDB2::singleton($dsn);
if (PEAR::isError($this->link)) {
die("There was an error connecting to the database: " . $this->link->getMessage());
}
}
示例8: __construct
/**
* Create a new instance of a report factory.
*/
public function __construct()
{
$this->setStorage();
$this->loadedPaths = array();
$this->db = MDB2::singleton();
//I2CE::pearError($this->db,"Cannot connect to DB");
$this->classCache = array();
}
示例9: open_connection
function open_connection($conn = DB_DNS)
{
//initialize MDB2
$this->mdb2 =& MDB2::singleton($conn);
$this->mdb2->loadModule('Extended');
$this->mdb2->loadModule('Date');
$this->mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
return $this->mdb2;
}
示例10: connect
function connect()
{
// connect to database
$options = array('portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL);
$this->dbc =& MDB2::singleton($this->_dsn, $options);
if (PEAR::isError($this->dbc)) {
return $this->dbc;
}
}
示例11: _install
protected function _install($table)
{
$db = MDB2::singleton(DB_URI);
$ret = $db->exec('ALTER TABLE `' . $table . '` ADD `archiver_archived` BOOL NOT NULL');
if (!PEAR::isError($ret)) {
$this->line('added field to ' . $table);
return true;
} else {
$this->line('Field already added to ' . $table);
}
}
示例12: getDBConnection
function getDBConnection()
{
$dsn = array('phptype' => 'mysql', 'hostspec' => 'localhost', 'database' => 'cicada', 'username' => 'root', 'password' => '');
$options = array('debug' => 2);
$mdb2 =& MDB2::singleton($dsn, $options);
if (PEAR::isError($mdb2)) {
die($mdb2->getMessage());
}
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
return $mdb2;
}
示例13: DB_Sql
function DB_Sql($dbhost = '', $dbuser = '', $dbpass = '', $dbname = '')
{
if (empty($dbhost) or empty($dbuser) or empty($dbpass) or empty($dbname)) {
$this->db = MDB2::singleton(DB_DSN);
} else {
$this->db = MDB2::singleton('mysql://' . $dbuser . ':' . $dbpass . '@' . $dbhost . '/' . $dbname);
}
if (PEAR::isError($this->db)) {
die($this->db->getMessage() . ' ' . $this->db->getUserInfo());
}
$this->db->query('SET NAMES utf8');
}
示例14: new_MDB2_Driver_Common
function new_MDB2_Driver_Common()
{
$options = array("debug" => 2);
$db = MDB2::singleton(DB_DSN, $options);
if (PEAR::isError($db)) {
throw new Exception($db->getMessage());
}
$db->setOption("portability", MDB2_PORTABILITY_NONE);
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$db->exec("SET time_zone=\"-01:00\"");
$db->query('SET NAMES utf8');
return $db;
}
示例15: addLastModifiedColumn
/**
* Adds the last_modifed column to the uuid_map table if it is not there
* @returns true on success
*/
protected function addLastModifiedColumn()
{
$db = MDB2::singleton();
$rows = $db->queryAll("SHOW FULL COLUMNS FROM `uuid_map` WHERE Field='last_modifed'");
if (count($rows) > 0) {
I2CE::raiseError("uuid_map table already has last_modifed");
} else {
$qry_alter = "ALTER TABLE `uuid_map` ADD COLUMN `last_modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP;";
if (I2CE::pearError($db->exec($qry_alter), "Error adding parent_id, parent_form column to {$table} table:")) {
return false;
}
}
return true;
}