本文整理汇总了PHP中MDB::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP MDB::connect方法的具体用法?PHP MDB::connect怎么用?PHP MDB::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDB
的用法示例。
在下文中一共展示了MDB::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: LiveUser_Admin_Perm_Container_MDB_Simple
/**
* Constructor
*
* @access protected
* @param array full liveuser configuration array
* @return void
* @see LiveUser::factory()
*/
function LiveUser_Admin_Perm_Container_MDB_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']) && MDB::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['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($connectOptions['dsn'], $options);
} else {
$this->dbc =& MDB::connect($connectOptions['dsn'], $options);
}
if (!MDB::isError($this->dbc)) {
$this->init_ok = true;
}
}
}
}
示例2: testSetDbInstanceDefault
function testSetDbInstanceDefault()
{
$db =& MDB::connect(DB_DSN, $GLOBALS['DB_OPTIONS']);
$qt =& new MDB_QueryTool();
$qt->setDbInstance($db);
$dbActual =& $qt->getDbInstance();
$this->assertEqual($db->fetchmode, $dbActual->fetchmode);
}
示例3: test_default
/**
* Check if the two instances are the same by comparing
* the fetchMode, since this is the easiest to compare if
* two objects are the same in PHP4.
* We can do that since the querytool sets the fetch mode to
* MDB_FETCHMODE_ASSOC.
* Not very nice but it works.
*
*/
function test_default()
{
$db =& MDB::connect(DB_DSN);
$qt =& new MDB_QueryTool();
$qt->setDbInstance($db);
$dbActual =& $qt->getDbInstance();
$this->assertEquals($db->fetchmode, $dbActual->fetchmode);
}
示例4: MetabaseSetupDatabaseObject
function MetabaseSetupDatabaseObject($arguments, &$db)
{
_convertArguments($arguments, $dsninfo, $options);
$db =& MDB::connect($dsninfo, $options);
if (MDB::isError($db) || !is_object($db)) {
return $db->getMessage();
}
return '';
}
示例5:
/**
* Connects to the db
*
* @return object DB The database object
* @access private
*/
function &_db_Connect($dsn)
{
$this->_debugMessage('_db_Connect($dsn)');
if (is_object($this->db)) {
return $this->db;
}
$db =& MDB::connect($dsn);
$this->_testFatalAbort($db, __FILE__, __LINE__);
return $db;
}
示例6: setUp
function setUp()
{
$this->dsn = $GLOBALS['dsn'];
$this->options = $GLOBALS['options'];
$this->database = $GLOBALS['database'];
$this->db =& MDB::connect($this->dsn, $this->options);
if (MDB::isError($this->db)) {
$this->assertTrue(false, 'Could not connect to database in setUp');
exit;
}
$this->db->setDatabase($this->database);
$this->fields = array('user_name', 'user_password', 'subscribed', 'user_id', 'quota', 'weight', 'access_date', 'access_time', 'approved');
$this->types = array('text', 'text', 'boolean', 'integer', 'decimal', 'float', 'date', 'time', 'timestamp');
$this->clearTables();
}
示例7: _connect
/**
* Connect to database by using the given DSN string
*
* @access private
* @param mixed DSN string | array | mdb object
* @return mixed Object on error, otherwise bool
*/
function _connect($dsn)
{
if (is_string($dsn) || is_array($dsn)) {
$this->db =& MDB::connect($dsn, $this->options['db_options']);
} elseif (is_a($dsn, 'mdb_common')) {
$this->db = $dsn;
} elseif (is_object($dsn) && MDB::isError($dsn)) {
return PEAR::raiseError($dsn->getMessage(), $dsn->code);
} else {
return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, 41, PEAR_ERROR_RETURN, null, null);
}
if (MDB::isError($this->db) || PEAR::isError($this->db)) {
return PEAR::raiseError($this->db->getMessage(), $this->db->code);
}
return true;
}
示例8: _connect
/**
* Connect to database by using the given DSN string
*
* @param mixed &$db DSN string | array | mdb object
*
* @return boolean|PEAR_Error on error
* @access private
*/
function _connect(&$db)
{
if (is_object($db) && is_a($db, 'MDB_Common')) {
$this->db =& $db;
} elseif (is_string($db) || is_array($db)) {
include_once 'MDB.php';
$this->db =& MDB::connect($db);
} elseif (is_object($db) && MDB::isError($db)) {
return PEAR::raiseError($db->getMessage(), $db->code);
} else {
return PEAR::raiseError('The given dsn was not valid in file ' . __FILE__ . ' at line ' . __LINE__, TRANSLATION2_ERROR_CANNOT_CONNECT, PEAR_ERROR_RETURN);
}
if (PEAR::isError($this->db)) {
return $this->db;
}
return true;
}
示例9: set
/**
* Init MDB container
*
* @access public
* @return void
* @throws HTTP_FloodControl_Exception if it is impossible to establish database connection.
*/
public function set()
{
$dsn = $this->_options['dsn'];
if (is_string($dsn) || is_array($dsn)) {
$this->_db = MDB::connect($dsn);
} else {
if (is_object($dsn) && is_a($dsn, 'mdb_common')) {
$this->_db = $dsn;
} else {
throw new HTTP_FloodControl_Exception('Incorrect DSN.');
}
}
if (PEAR::isError($this->_db)) {
throw new HTTP_FloodControl_Exception($this->_db->getMessage(), $this->_db->getCode());
}
}
示例10: _connect
/**
* Connect to database by using the given DSN string
*
* @param string $dsn DSN string
*
* @access private
* @return mixed Object on error, otherwise bool
*/
function _connect($dsn)
{
if (is_string($dsn) || is_array($dsn)) {
$this->db = MDB::connect($dsn);
} else {
if (is_object($dsn) && is_a($dsn, 'mdb_common')) {
$this->db = $dsn;
} else {
if (is_object($dsn) && MDB::isError($dsn)) {
return new MDB_Error($dsn->code, PEAR_ERROR_DIE);
} else {
return new PEAR_Error("The given dsn was not valid in file " . __FILE__ . " at line " . __LINE__, 41, PEAR_ERROR_RETURN, null, null);
}
}
}
if (MDB::isError($this->db)) {
return new MDB_Error($this->db->code, PEAR_ERROR_DIE);
}
return true;
}
示例11: LiveUser_Auth_Container_MDB
/**
* Class constructor.
*
* @see LiveUser::factory()
* @access protected
* @param array configuration array
* @return void
*/
function LiveUser_Auth_Container_MDB(&$connectOptions)
{
$this->LiveUser_Auth_Common($connectOptions);
if (is_array($connectOptions)) {
$this->LiveUser_Auth_Common($connectOptions);
if (isset($connectOptions['connection']) && MDB::isConnection($connectOptions['connection'])) {
$this->dbc =& $connectOptions['connection'];
$this->init_ok = true;
} elseif (isset($connectOptions['dsn'])) {
$this->dsn = $connectOptions['dsn'];
$function = null;
if (isset($connectOptions['function'])) {
$function = $connectOptions['function'];
}
$options = null;
if (isset($connectOptions['options'])) {
$options = $connectOptions['options'];
}
$options['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($connectOptions['dsn'], $options);
} else {
$this->dbc =& MDB::connect($connectOptions['dsn'], $options);
}
if (!MDB::isError($this->dbc)) {
$this->init_ok = true;
}
}
}
}
示例12: die
}
echo $db_type . '<br>';
// Data Source Name: This is the universal connection string
$dsn['username'] = $user;
$dsn['password'] = $pass;
$dsn['hostspec'] = $host;
$dsn['phptype'] = $db_type;
// MDB::connect will return a Pear DB object on success
// or a Pear MDB error object on error
// You can also set to TRUE the second param
// if you want a persistent connection:
// $db = MDB::connect($dsn, TRUE);
// you can alternatively build a dsn here
//$dsn = "$db_type://$user:$pass@$host/$db_name";
Var_Dump::display($dsn);
$db =& MDB::connect($dsn);
// With MDB::isError you can differentiate between an error or
// a valid connection.
if (MDB::isError($db)) {
die(__LINE__ . $db->getMessage());
}
$manager =& new MDB_Manager();
$input_file = 'metapear_test_db.schema';
// you can either pass a dsn string, a dsn array or an exisiting db connection
$manager->connect($db);
// lets create the database using 'metapear_test_db.schema'
// if you have allready run this script you should have 'metapear_test_db.schema.before'
// in that case MDB will just compare the two schemas and make any necessary modifications to the existing DB
echo Var_Dump::display($manager->updateDatabase($input_file, $input_file . '.before')) . '<br>';
echo 'updating database from xml schema file<br>';
echo 'switching to database: ' . $db_name . '<br>';
示例13: init
/**
* Load the storage container
*
* @param mixed &$conf Name of array containing the configuration.
* @param string $containerName name of the container that should be used
* @return boolean true on success or false on failure
*
* @access public
*/
function init(&$conf, $containerName)
{
parent::init($conf, $containerName);
if (is_array($conf['storage'])) {
if (isset($conf['storage']['connection']) && MDB::isConnection($conf['storage']['connection'])) {
$this->dbc =& $conf['storage']['connection'];
} elseif (isset($conf['storage']['dsn'])) {
$this->dsn = $conf['storage']['dsn'];
$function = null;
if (isset($conf['storage']['function'])) {
$function = $conf['storage']['function'];
}
$options = null;
if (isset($conf['storage']['options'])) {
$options = $conf['storage']['options'];
}
$options['optimize'] = 'portability';
if ($function == 'singleton') {
$this->dbc =& MDB::singleton($conf['storage']['dsn'], $options);
} else {
$this->dbc =& MDB::connect($conf['storage']['dsn'], $options);
}
if (PEAR::isError($this->dbc)) {
$this->_stack->push(LIVEUSER_ERROR_INIT_ERROR, 'error', array('container' => 'could not connect: ' . $this->dbc->getMessage()));
return false;
}
}
}
return true;
}
示例14: connect
/**
* use this method if you want to connect manually
* @param mixed $dsn DSN string, DSN array or MDB object
* @param array $options
*/
function connect($dsn, $options = array())
{
if (is_object($dsn)) {
$res = $this->db =& $dsn;
} else {
$res = $this->db =& MDB::connect($dsn, $options);
}
if (MDB::isError($res)) {
// FIXXME what shall we do here?
$this->_errorLog($res->getUserInfo());
} else {
$this->db->setFetchMode(MDB_FETCHMODE_ASSOC);
}
}
示例15: array
<?php
require_once 'MDB.php';
require_once 'LiveUser.php';
// Plase configure the following file according to your environment
$db_user = 'user';
$db_pass = 'pass';
$db_host = 'localhost';
$db_name = 'pear_test';
$dsn = "mysql://{$db_user}:{$db_pass}@{$db_host}/{$db_name}";
$db = MDB::connect($dsn, array('sequence_col_name' => 'id'));
if (MDB::isError($db)) {
echo $db->getMessage() . ' ' . $db->getUserInfo();
}
$db->setFetchMode(MDB_FETCHMODE_ASSOC);
$conf = array('autoInit' => true, 'session' => array('name' => 'PHPSESSION', 'varname' => 'ludata'), 'login' => array('method' => 'post', 'username' => 'handle', 'password' => 'passwd', 'force' => false, 'function' => '', 'remember' => 'rememberMe'), 'logout' => array('trigger' => 'logout', 'redirect' => 'home.php', 'destroy' => true, 'method' => 'get', 'function' => ''), 'authContainers' => array(array('type' => 'MDB', 'name' => 'MDB_Local', 'loginTimeout' => 0, 'expireTime' => 3600, 'idleTime' => 1800, 'dsn' => $dsn, 'allowDuplicateHandles' => 0, 'authTable' => 'liveuser_users', 'authTableCols' => array('user_id' => array('name' => 'auth_user_id', 'type' => 'text'), 'handle' => array('name' => 'handle', 'type' => 'text'), 'passwd' => array('name' => 'passwd', 'type' => 'text'), 'lastlogin' => array('name' => 'lastlogin', 'type' => 'timestamp'), 'is_active' => array('name' => 'is_active', 'type' => 'boolean'), 'owner_user_id' => array('name' => 'owner_user_id', 'type' => 'integer'), 'owner_group_id' => array('name' => 'owner_group_id', 'type' => 'integer')))), 'permContainer' => array('dsn' => $dsn, 'type' => 'MDB_Medium', 'prefix' => 'liveuser_'));
function logOut()
{
}
function logIn()
{
}
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$usr = LiveUser::singleton($conf);
$usr->setLoginFunction('logIn');
$usr->setLogOutFunction('logOut');
$e = $usr->init();
if (PEAR::isError($e)) {
//var_dump($usr);
die($e->getMessage() . ' ' . $e->getUserinfo());
}