本文整理汇总了PHP中MDB2::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP MDB2::factory方法的具体用法?PHP MDB2::factory怎么用?PHP MDB2::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDB2
的用法示例。
在下文中一共展示了MDB2::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Klutz_Driver_sql
/**
* Constructs a new SQL storage object.
*
* @param array $params A hash containing connection parameters.
*/
function Klutz_Driver_sql($params = array())
{
if (empty($params['basedir'])) {
return null;
}
$this->basedir = $params['basedir'];
if (substr($this->basedir, -1, 1) != "/") {
$this->basedir .= "/";
}
/* Setup the database */
$config = $GLOBALS['conf']['sql'];
unset($config['charset']);
$this->_db = MDB2::factory($config);
$this->_db->setOption('seqcol_name', 'id');
}
示例2: db_init
function db_init($user, $passwd, $host, $database, $die_on_error = TRUE, $charset = "UTF8")
{
global $db;
// DSN string must have new_link=true in order for multiple connections with different charsets to work
$dsn = "mysql://{$user}:{$passwd}@{$host}/{$database}?new_link=true";
$db = MDB2::factory($dsn);
if (PEAR::isError($db)) {
$msg = "Unable to initialise database. Please try again later.";
$msg = "{$msg}: {$db->message} . ' ' . {$db->userinfo}";
$db = NULL;
db_log(1, $msg);
if ($die_on_error) {
if (defined('UNIT_TEST')) {
print $msg . "\n";
}
exit;
}
} else {
$db->setCharset($charset);
// remove MDB2_PORTABILITY_EMPTY_TO_NULL - Without turning this setting off, MDB2 will treat empty strings (i.e. '')
// as NULLs when storing. We prefer to use empty strings for some fields.
// remove MDB2_PORTABILITY_FIX_CASE - keep associative fields case sensitive rather than all lower case
$db->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL ^ MDB2_PORTABILITY_FIX_CASE);
}
}
示例3: connect
/**
* connect()
*
* @access public
* @param string $sDsn
* @param mixed $mOptions boolean | array
* @return mixed boolean | MDB2_Error
*/
function connect($sDsn, $mOptions = array())
{
if (isset($this->_aryConn[$sDsn])) {
$mRet = $this->setOptions($sDsn, $mOptions);
if (MDB2::isError($mRet)) {
return $mRet;
}
$this->_aryConn[$sDsn]->debug_output = '';
return true;
}
if (!is_array($mOptions)) {
$mOptions = array('persistent' => $mOptions);
}
$this->_aryConn[$sDsn] = MDB2::factory($sDsn, $mOptions);
if (MDB2::isError($this->_aryConn[$sDsn])) {
$objConn = $this->_aryConn[$sDsn];
unset($this->_aryConn[$sDsn]);
return $objConn;
}
$this->_aryConn[$sDsn]->loadModule('Date');
$this->_aryConn[$sDsn]->loadModule('Extended');
$this->_aryConn[$sDsn]->setFetchMode(MDB2_FETCHMODE_ASSOC);
$this->_aryConn[$sDsn]->setCharset('UTF8');
$this->_aryConn[$sDsn]->debug_output = '';
return true;
}
示例4: createInstance
public function createInstance()
{
require_once 'MDB2.php';
$dsn = $this->settings['db.dsn'];
$db = MDB2::factory($dsn);
return $db;
}
示例5: conectar
function conectar()
{
if (!isset($mdb2)) {
//Local
$db_name = 'root';
$db_password = '';
$db_server = 'localhost';
$db_database = 'coopcrucial';
//Nabica
/*$db_name = 'coopcrucial';
$db_password = 'Nabica2012';
$db_server = 'coopcrucial.db.5840507.hostedresource.com';
$db_database = 'coopcrucial';*/
$dsn = 'mysql://' . $db_name . ':' . $db_password . '@' . $db_server . '/' . $db_database;
try {
$mdb2 =& MDB2::factory($dsn, true);
if (MDB2::isError($mdb2)) {
die($mdb2->getmessage() . ' - ' . $mdb2->getUserInfo());
} else {
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);
}
$mdb2 = array('mdb2' => $mdb2, 'dsn' => $dsn);
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
}
return $mdb2;
}
示例6: dbh
public function dbh($dsn = null, $opt = null)
{
//init
if (null != $dsn) {
$this->dsn = $dsn;
}
if (null != $opt) {
$this->opt = $opt;
}
//connect => $dsn = 'pgsql://someuser:apasswd@localhost/thedb';
$this->dbh =& MDB2::factory($this->dsn, $this->opt);
//sanity
if (self::err($this->dbh, "dbh() : init-db")) {
return null;
}
//re-init
$this->dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
//more options
$this->dbh->setOption('result_buffering', true);
$this->dbh->setOption('multi_query', true);
//set here the utf-8
$utf8[] = " SET NAMES 'utf8' COLLATE utf8_unicode_ci ";
$utf8[] = " SET character_set_client='utf8' ";
$utf8[] = " SET character_set_connection='utf8' ";
for ($i = 0; $i < @count($utf8); $i++) {
$bfsql = trim($utf8[$i]);
self::query($bfsql, "ERROR: {$bfsql}");
}
//give it back ;-)
return $this->dbh;
}
示例7: __construct
private function __construct()
{
Plank_Logger::log('Singleton', get_class($this) . ' singleton created.', L_TRACE);
$config = Plank_Config::getInstance();
$config = $config->getArea('database');
if (!$config || !isset($config['connections'])) {
throw new Plank_Exception_Database_Config('Databases not configured');
}
$connections = explode(',', $config['connections']);
foreach ($connections as $connection) {
if (isset($config['dsn_' . $connection])) {
$this->connections[$connection] = MDB2::factory($config['dsn_' . $connection]);
if (PEAR::isError($this->connections[$connection])) {
throw new Plank_Exception_Database('DB Error! ' . $this->connections[$connection]->getMessage() . ' ' . $this->connections[$connection]->getUserInfo());
}
if (SHOWDEBUG) {
$this->connections[$connection]->setOption('debug', 1);
$this->connections[$connection]->setOption('log_line_break', "<br/>");
}
$this->connections[$connection]->setOption('portability', MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_FIX_CASE);
$this->connections[$connection]->setFetchMode(MDB2_FETCHMODE_ASSOC);
if (PEAR::isError($this->connections[$connection])) {
throw new Plank_Exception_Database_Connection('Error connecting ' . $connection . ': ' . $this->connections[$connection]->getMessage() . ' ' . $this->connections[$connection]->getUserInfo());
}
} else {
throw new Plank_Exception_Database_Config('No DSN for DB Connection ' . $connection);
}
}
}
示例8: array
/**
* This function is a replacement for ADONewConnection, it does some
* basic additional configuration and prepares the table prefix stuff
*
* @param $conf usually $conf['database'] in Flyspray
* @return object
*/
function &NewDatabase($conf = array())
{
if (!is_array($conf) || extract($conf, EXTR_REFS | EXTR_SKIP) < 5) {
die('Flyspray was unable to connect to the database. ' . 'Check your settings in flyspray.conf.php');
}
$dbpass = rawurlencode($dbpass);
if ($dbtype == 'sqlite') {
$dsn = "{$dbtype}:///{$dbname}?mode=0666";
} else {
$dsn = "{$dbtype}://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}?charset=utf8";
}
$db =& MDB2::factory($dsn);
$db->loadModule('Extended', 'x', false);
if (defined('IN_UPGRADER') || defined('IN_SETUP')) {
$db->loadModule('Manager');
}
$dbprefix = isset($dbprefix) ? $dbprefix : '';
if ($db === false || !empty($dbprefix) && !preg_match('/^[a-z][a-z0-9_]+$/i', $dbprefix)) {
die('Flyspray was unable to connect to the database. ' . 'Check your settings in flyspray.conf.php');
}
define('DB_PREFIX', $dbprefix);
$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$db->setOption('debug', true);
$db->setOption('debug_handler', '_table_prefix');
$db->setOption('quote_identifier', true);
// upgrader can handle that on its own
if (!defined('IN_UPGRADER') && !defined('IN_SETUP') || defined('DEBUG_SQL')) {
$db->setErrorHandling(PEAR_ERROR_CALLBACK, 'show_dberror');
}
return $db;
}
示例9: connectDbLazy
/**
* Connect to databases, but create instance not before the first time
* a query gets executed.
*/
private function connectDbLazy()
{
$this->connection = MDB2::factory($this->dsn);
if (PEAR::isError($this->connection)) {
die("Error while lazy connecting: " . $this->connection->getMessage() . "\ndsn was: " . print_r($this->dsn) . "\n");
}
}
示例10: myDB
public function myDB($host, $user, $pwd, $db, $port)
{
$dsn = array('phptype' => 'pgsql', 'username' => $user, 'password' => $pwd, 'hostspec' => $host, 'database' => $db, 'port' => $port);
if ($this->log) {
$this->writeLog(print_r($dsn, true));
}
$options = array('result_buffering' => false);
$this->db =& MDB2::factory($dsn, $options);
//$this->db=& MDB2::connect($dsn,$options);
if (!$this->db || PEAR::isError($this->db)) {
if ($this->log) {
$this->writeLog('Connect Error: ' . $dns);
}
$this->dbFehler('Connect ' . print_r($dsn, true), $this->db->getMessage());
die($this->db->getMessage());
}
$this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
if ($this->log) {
$this->writeLog('Connect: ok ');
}
$sql = 'SELECT version()';
$rs = $this->getOne($sql);
if ($this->log) {
$this->writeLog(print_r($rs, true));
}
preg_match('/PostgreSQL\\s*([\\d]+)\\.([\\d]+)\\..*/', $rs['version'], $ver);
if ($ver[1] == '9' and $ver[2] >= '3' or $ver[1] >= '10') {
$this->JVer = true;
}
if ($this->log) {
$this->writeLog(print_r($ver, true) . "!" . $this->JVer . '!');
}
return $this->db;
}
示例11: connect
public function connect($dsn, $type = false, $options = false)
{
// Currently there are only two options: pear_mdb2 and php_native_mysql
$connected = false;
if ($type == 'php_native_mysql') {
$this->db = mysql_connect($dsn->hostspec, $dsn->username, $dsn->password);
if ($this->db) {
if ($dsn->database) {
mysql_select_db($dsn->database, $this->db);
}
$this->dsn = $dsn;
$connected = true;
}
} else {
if ($type == 'pear_mdb2') {
require_once 'MDB2.php';
$this->db =& MDB2::factory($dsn, $options);
if (PEAR::isError($this->db)) {
$this->errors[] = $this->db->getMessage();
} else {
$connected = true;
$this->db->setFetchMode(MDB2_FETCHMODE_ASSOC);
}
}
}
if (!$connected) {
$errors[] = 'Unable to connect to database using type: ' . $type;
return false;
} else {
return $this->db;
}
}
示例12: init
/**
|
| @init
|
| @description
| - init
|
| @parameters
| -
|
|
| @return
| -
|
**/
public function init()
{
//create connection
debug("init() : start init [ self::{$_Dsn} ]");
//try
self::$_Mdb =& MDB2::factory(self::$_Dsn, self::$_Opt);
//sanity-chk
if (self::err(self::$_Mdb, "init::FAILED")) {
return null;
}
//misc options set here
self::$_Mdb->setFetchMode(MDB2_FETCHMODE_ASSOC);
//more options
self::$_Mdb->setOption('result_buffering', true);
self::$_Mdb->setOption('multi_query', true);
//set here the utf-8
$utf8[] = " SET NAMES 'utf8' COLLATE utf8_unicode_ci ";
$utf8[] = " SET character_set_client='utf8' ";
$utf8[] = " SET character_set_connection='utf8' ";
for ($i = 0; $i < @count($utf8); $i++) {
$bfsql = trim($utf8[$i]);
self::query($bfsql, "ERROR: {$bfsql}");
debug("init() : utf-8 [ {$bfsql} ]");
}
debug("init() : done init [ self::{$_Mdb} ]");
return self::$_Mdb;
}
示例13: __construct
public function __construct()
{
$dsn = DB_TYPE . "://" . DB_USER . ":" . DB_PASS . "@" . DB_HOST . "/" . DB_DATABASE;
$this->mdb2 =& MDB2::factory($dsn);
if (PEAR::isError($this->mdb2)) {
die($this->mdb2->getMessage());
}
}
示例14: __construct
function __construct($dsn)
{
$this->dbh =& MDB2::factory($dsn);
if (PEAR::isError($this->dbh)) {
die($this->dbh->getMessage());
}
$this->dbh->setFetchMode(MDB2_FETCHMODE_ASSOC);
}
示例15: tearDown
function tearDown()
{
$db = MDB2::factory(DB_DSN);
$db->query('TRUNCATE langtkursus_tilmelding_ny');
$db->query('TRUNCATE langtkursus_rate');
$db->query('TRUNCATE langtkursus_tilmelding_rate');
$db->query('TRUNCATE betaling');
}