本文整理汇总了PHP中xPDO::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::connect方法的具体用法?PHP xPDO::connect怎么用?PHP xPDO::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDO
的用法示例。
在下文中一共展示了xPDO::connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testConnectionError
public function testConnectionError()
{
$string_dsn = $this->properties[$this->properties['xpdo_driver'] . '_string_dsn_error'];
$mypdo = new xPDO($string_dsn, "nonesuchuser", "nonesuchpass");
$result = $mypdo->connect();
// Should be an error set since we gave bogus info
$this->assertTrue($result == false, "Connection was successful with bogus information.");
}
示例2: testConnectionError
/**
* Test for a bogus false connection.
*
* @TODO Fix this, it seems to cause a timeout and a stall of PHPUnit.
*/
public function testConnectionError()
{
if (!empty(xPDOTestHarness::$debug)) {
print "\n" . __METHOD__ . " = ";
}
$string_dsn = xPDOTestHarness::$properties[xPDOTestHarness::$properties['xpdo_driver'] . '_string_dsn_error'];
$mypdo = new xPDO($string_dsn, "nonesuchuser", "nonesuchpass");
$result = $mypdo->connect();
// Should be an error set since we gave bogus info
$this->assertTrue($result == false, "Connection was successful with bogus information.");
}
示例3: getConnection
/**
* Get an xPDO connection to the database.
*
* @param int $mode
* @return xPDO A copy of the xpdo object.
*/
public function getConnection($mode = 0)
{
if ($this->settings && empty($mode)) {
$mode = (int) $this->settings->get('installmode');
}
if (empty($mode)) {
$mode = modInstall::MODE_NEW;
}
if ($mode === modInstall::MODE_UPGRADE_REVO) {
$errors = array();
$this->xpdo = $this->_modx($errors);
} else {
if (!is_object($this->xpdo)) {
$options = array();
if ($this->settings->get('new_folder_permissions')) {
$options['new_folder_permissions'] = $this->settings->get('new_folder_permissions');
}
if ($this->settings->get('new_file_permissions')) {
$options['new_file_permissions'] = $this->settings->get('new_file_permissions');
}
$this->xpdo = $this->_connect($this->settings->get('database_dsn'), $this->settings->get('database_user'), $this->settings->get('database_password'), $this->settings->get('table_prefix'), $options);
if (!$this->xpdo instanceof xPDO) {
return $this->xpdo;
}
$this->xpdo->setOption('cache_path', MODX_CORE_PATH . 'cache/');
if ($mode === modInstall::MODE_UPGRADE_REVO_ADVANCED) {
if ($this->xpdo->connect()) {
$errors = array();
$this->xpdo = $this->_modx($errors);
} else {
return $this->lexicon('db_err_connect_upgrade');
}
}
}
}
if (is_object($this->xpdo) && $this->xpdo instanceof xPDO) {
$this->xpdo->setLogTarget(array('target' => 'FILE', 'options' => array('filename' => 'install.' . MODX_CONFIG_KEY . '.' . strftime('%Y-%m-%dT%H.%M.%S') . '.log')));
$this->xpdo->setLogLevel(xPDO::LOG_LEVEL_ERROR);
$this->xpdo->setPackage('modx', MODX_CORE_PATH . 'model/', $this->settings->get('table_prefix'));
}
return $this->xpdo;
}