当前位置: 首页>>代码示例>>PHP>>正文


PHP xPDO::parseDSN方法代码示例

本文整理汇总了PHP中xPDO::parseDSN方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::parseDSN方法的具体用法?PHP xPDO::parseDSN怎么用?PHP xPDO::parseDSN使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xPDO的用法示例。


在下文中一共展示了xPDO::parseDSN方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: removeSourceContainer

 public function removeSourceContainer($dsnArray = null, $username = null, $password = null)
 {
     $removed = false;
     if ($this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
         if ($dsnArray === null) {
             $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn'));
         }
         if (is_array($dsnArray)) {
             try {
                 $dbfile = $dsnArray['dbname'];
                 if (file_exists($dbfile)) {
                     $removed = unlink($dbfile);
                     if (!$removed) {
                         $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container");
                     }
                 } else {
                     $removed = true;
                 }
             } catch (Exception $e) {
                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container: " . $e->getMessage());
             }
         }
     }
     return $removed;
 }
开发者ID:DeFi-ManriquezLuis,项目名称:MTLTransfer,代码行数:25,代码来源:xpdomanager.class.php

示例2: removeSourceContainer

 public function removeSourceContainer($dsnArray = null, $username = null, $password = null)
 {
     $removed = false;
     if ($dsnArray === null) {
         $dsnArray = xPDO::parseDSN($this->xpdo->getOption('dsn'));
     }
     if ($username === null) {
         $username = $this->xpdo->getOption('username', null, '');
     }
     if ($password === null) {
         $password = $this->xpdo->getOption('password', null, '');
     }
     if (is_array($dsnArray) && is_string($username) && is_string($password)) {
         $sql = 'DROP DATABASE ' . $this->xpdo->escape($dsnArray['dbname']);
         try {
             $pdo = new PDO("mysql:host={$dsnArray['host']}", $username, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
             $result = $pdo->exec($sql);
             if ($result !== false) {
                 $removed = true;
             } else {
                 $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container:\n{$sql}\nresult = " . var_export($result, true));
             }
         } catch (PDOException $pe) {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not connect to database server: " . $pe->getMessage());
         } catch (Exception $e) {
             $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not remove source container: " . $e->getMessage());
         }
     }
     return $removed;
 }
开发者ID:JoeBlow,项目名称:revolution,代码行数:30,代码来源:xpdomanager.class.php

示例3: testInitialize

 public function testInitialize()
 {
     $xpdo = $this->getXPDOObject();
     if ($xpdo && $xpdo->connect()) {
         $response = $xpdo->getManager()->removeSourceContainer(xPDO::parseDSN($this->properties[$this->properties['xpdo_driver'] . '_string_dsn_test']));
         if ($response) {
             $xpdo = null;
         }
     } else {
         $xpdo = null;
     }
     $this->assertTrue($xpdo == null, "Test container exists and could not be removed for initialization");
 }
开发者ID:christianseel,项目名称:xpdo,代码行数:13,代码来源:XPDOTest.php

示例4: testRemoveSourceContainer

 /**
  * Verify drop database works.
  */
 public function testRemoveSourceContainer()
 {
     if (!empty(xPDOTestHarness::$debug)) {
         print "\n" . __METHOD__ . " = ";
     }
     $xpdo = xPDOTestHarness::getInstance(true);
     $success = false;
     if ($xpdo) {
         $driver = xPDOTestHarness::$properties['xpdo_driver'];
         $dsn = xPDOTestHarness::$properties[$driver . '_string_dsn_test'];
         $dsn = xPDO::parseDSN($dsn);
         $success = $xpdo->getManager()->removeSourceContainer($dsn);
     }
     $this->assertTrue($success, "Test container exists and could not be removed for initialization via xPDOManager->removeSourceContainer()");
 }
开发者ID:node-migrator-bot,项目名称:xpdo,代码行数:18,代码来源:xPDOTearDown.php

示例5: testInitialize

 public function testInitialize()
 {
     if (!empty(xPDOTestHarness::$debug)) {
         print "\n" . __METHOD__ . " = ";
     }
     $xpdo = xPDOTestHarness::getInstance(true);
     if (is_object($xpdo)) {
         $response = $xpdo->getManager()->removeSourceContainer(xPDO::parseDSN(xPDOTestHarness::$properties[xPDOTestHarness::$properties['xpdo_driver'] . '_string_dsn_test']));
         if ($response) {
             $xpdo = null;
         }
     } else {
         $xpdo = null;
     }
     $this->assertTrue($xpdo == null, "Test container exists and could not be removed for initialization");
 }
开发者ID:christianseel,项目名称:xpdo,代码行数:16,代码来源:xPDOSetUp.php

示例6: createSourceContainer

 /**
  * Creates the physical data container represented by a data source
  *
  * @todo Refactor this to work on an xPDO instance rather than as a static call.
  */
 public function createSourceContainer($dsn, $username = '', $password = '', $containerOptions = null)
 {
     $created = false;
     if ($dsnArray = xPDO::parseDSN($dsn)) {
         switch ($dsnArray['dbtype']) {
             case 'mysql':
                 include_once strtr(realpath(dirname(__FILE__)), '\\', '/') . '/mysql/xpdomanager.class.php';
                 $created = xPDOManager_mysql::createSourceContainer($dsnArray, $username, $password, $containerOptions);
                 break;
             case 'sqlite':
                 include_once strtr(realpath(dirname(__FILE__)), '\\', '/') . '/sqlite/xpdomanager.class.php';
                 $created = xPDOManager_sqlite::createSourceContainer($dsnArray, $username, $password, $containerOptions);
                 break;
             case 'pgsql':
                 include_once strtr(realpath(dirname(__FILE__)), '\\', '/') . '/pgsql/xpdomanager.class.php';
                 $created = xPDOManager_pgsql::createSourceContainer($dsnArray, $username, $password, $containerOptions);
                 break;
             default:
                 break;
         }
     }
     return $created;
 }
开发者ID:Kleist,项目名称:xPDO,代码行数:28,代码来源:xpdomanager.class.php

示例7: parseDSN

    'modUserMessage',
    'modUserRole',
    'modUserSetting',
    'modWorkspace',
    'registry.db.modDbRegisterMessage',
    'registry.db.modDbRegisterTopic',
    'registry.db.modDbRegisterQueue',
    'transport.modTransportPackage',
    'transport.modTransportProvider',
);

$this->xpdo->getManager();
$connected= $this->xpdo->connect();
$created= false;
if (!$connected) {
    $dsnArray= xPDO :: parseDSN($this->xpdo->getOption('dsn'));
    $containerOptions['charset']= $install->settings->get('database_charset', 'utf8');
    $containerOptions['collation']= $install->settings->get('database_collation', 'utf8_general_ci');
    $created= $this->xpdo->manager->createSourceContainer($dsnArray, $this->xpdo->config['username'], $this->xpdo->config['password'], $containerOptions);
    if (!$created) {
        $results[]= array ('class' => 'failed', 'msg' => '<p class="notok">'.$this->lexicon('db_err_create').'</p>');
    }
    else {
        $connected= $this->xpdo->connect();
    }
    if ($connected) {
        $results[]= array ('class' => 'success', 'msg' => '<p class="ok">'.$this->lexicon('db_created').'</p>');
    }
}
if ($connected) {
    ob_start();
开发者ID:ncrossland,项目名称:revolution,代码行数:31,代码来源:tables_create.php

示例8: __construct

 /**
  * Construct a new xPDOConnection instance.
  *
  * @param xPDO $xpdo A reference to a valid xPDO instance to attach to.
  * @param string $dsn A string representing the DSN connection string.
  * @param string $username The database username credentials.
  * @param string $password The database password credentials.
  * @param array $options An array of xPDO options for the connection.
  * @param array $driverOptions An array of PDO driver options for the connection.
  */
 public function __construct(xPDO &$xpdo, $dsn, $username = '', $password = '', $options = array(), $driverOptions = array())
 {
     $this->xpdo =& $xpdo;
     if (is_array($this->xpdo->config)) {
         $options = array_merge($this->xpdo->config, $options);
     }
     if (!isset($options[xPDO::OPT_TABLE_PREFIX])) {
         $options[xPDO::OPT_TABLE_PREFIX] = '';
     }
     $this->config = array_merge($options, xPDO::parseDSN($dsn));
     $this->config['dsn'] = $dsn;
     $this->config['username'] = $username;
     $this->config['password'] = $password;
     $driverOptions = is_array($driverOptions) ? $driverOptions : array();
     if (array_key_exists('driverOptions', $this->config) && is_array($this->config['driverOptions'])) {
         $driverOptions = array_merge($this->config['driverOptions'], $driverOptions);
     }
     $this->config['driverOptions'] = $driverOptions;
     if (array_key_exists(xPDO::OPT_CONN_MUTABLE, $this->config)) {
         $this->_mutable = (bool) $this->config[xPDO::OPT_CONN_MUTABLE];
     }
 }
开发者ID:rossng,项目名称:revolution,代码行数:32,代码来源:xpdo.class.php

示例9: __construct

 /**
  * The xPDO Constructor.
  *
  * This method is used to create a new xPDO object with a connection to a
  * specific database container.
  *
  * @param mixed $dsn A valid DSN connection string.
  * @param string $username The database username with proper permissions.
  * @param string $password The password for the database user.
  * @param array|string $options An array of xPDO options. For compatibility with previous
  * releases, this can also be a single string representing a prefix to be applied to all
  * database container (i. e. table) names, to isolate multiple installations or conflicting
  * table names that might need to coexist in a single database container. It is preferrable to
  * include the table_prefix option in the array for future compatibility.
  * @param mixed $driverOptions Driver-specific PDO options.
  * @return xPDO A unique xPDO instance.
  */
 public function __construct($dsn, $username = '', $password = '', $options = array(), $driverOptions = null)
 {
     if (is_string($options)) {
         $options = array(xPDO::OPT_TABLE_PREFIX => $options);
     }
     if (!is_array($options)) {
         $options = array(xPDO::OPT_TABLE_PREFIX => '');
     }
     if (!isset($options[xPDO::OPT_TABLE_PREFIX])) {
         $options[xPDO::OPT_TABLE_PREFIX] = '';
     }
     $this->config = array_merge($options, xPDO::parseDSN($dsn));
     $this->config['dsn'] = $dsn;
     $this->config['username'] = $username;
     $this->config['password'] = $password;
     $this->config['driverOptions'] = is_array($driverOptions) ? $driverOptions : array();
     switch ($this->config['dbtype']) {
         case 'mysql':
             $this->_escapeCharOpen = "`";
             $this->_escapeCharClose = "`";
             break;
         case 'sqlite':
             $this->_escapeCharOpen = '"';
             $this->_escapeCharClose = '"';
             break;
         default:
             break;
     }
     $this->setPackage('om', XPDO_CORE_PATH, $this->config[xPDO::OPT_TABLE_PREFIX]);
     if (isset($this->config[xPDO::OPT_BASE_PACKAGES]) && !empty($this->config[xPDO::OPT_BASE_PACKAGES])) {
         $basePackages = explode(',', $this->config[xPDO::OPT_BASE_PACKAGES]);
         foreach ($basePackages as $basePackage) {
             $exploded = explode(':', $basePackage, 2);
             if ($exploded) {
                 $path = $exploded[1];
                 $prefix = null;
                 if (strpos($path, ';')) {
                     $details = explode(';', $path);
                     if ($details && count($details) == 2) {
                         $path = $details[0];
                         $prefix = $details[1];
                     }
                 }
                 $this->addPackage($exploded[0], $path, $prefix);
             }
         }
     }
     $this->getDriver();
     $this->loadClass('xPDOObject');
     $this->loadClass('xPDOSimpleObject');
     if (isset($this->config[xPDO::OPT_BASE_CLASSES])) {
         foreach (array_keys($this->config[xPDO::OPT_BASE_CLASSES]) as $baseClass) {
             $this->loadClass($baseClass);
         }
     }
     if (isset($this->config[xPDO::OPT_CACHE_PATH])) {
         $this->cachePath = $this->config[xPDO::OPT_CACHE_PATH];
     }
 }
开发者ID:JoeBlow,项目名称:revolution,代码行数:76,代码来源:xpdo.class.php

示例10: array

/**
 * Create a new MODX Revolution repository.
 *
 * @var xPDO $modx
 * @var modInstall $install
 * @var modInstallRunner $this
 *
 * @package setup
 */
$results = array();
$classes = array('modAccessAction', 'modAccessActionDom', 'modAccessCategory', 'modAccessContext', 'modAccessElement', 'modAccessMenu', 'modAccessPermission', 'modAccessPolicy', 'modAccessPolicyTemplate', 'modAccessPolicyTemplateGroup', 'modAccessResource', 'modAccessResourceGroup', 'modAccessTemplateVar', 'modAction', 'modActionDom', 'modActionField', 'modActiveUser', 'modCategory', 'modCategoryClosure', 'modChunk', 'modClassMap', 'modContentType', 'modContext', 'modContextResource', 'modContextSetting', 'modDashboard', 'modDashboardWidget', 'modDashboardWidgetPlacement', 'modElementPropertySet', 'modEvent', 'modExtensionPackage', 'modFormCustomizationProfile', 'modFormCustomizationProfileUserGroup', 'modFormCustomizationSet', 'modLexiconEntry', 'modManagerLog', 'modMenu', 'modNamespace', 'modPlugin', 'modPluginEvent', 'modPropertySet', 'modResource', 'modResourceGroup', 'modResourceGroupResource', 'modSession', 'modSnippet', 'modSystemSetting', 'modTemplate', 'modTemplateVar', 'modTemplateVarResource', 'modTemplateVarResourceGroup', 'modTemplateVarTemplate', 'modUser', 'modUserProfile', 'modUserGroup', 'modUserGroupMember', 'modUserGroupRole', 'modUserGroupSetting', 'modUserMessage', 'modUserSetting', 'modWorkspace', 'registry.db.modDbRegisterMessage', 'registry.db.modDbRegisterTopic', 'registry.db.modDbRegisterQueue', 'transport.modTransportPackage', 'transport.modTransportProvider', 'sources.modAccessMediaSource', 'sources.modMediaSource', 'sources.modMediaSourceElement', 'sources.modMediaSourceContext');
$modx->getManager();
$connected = $modx->connect();
$created = false;
if (!$connected) {
    $dsnArray = xPDO::parseDSN($modx->getOption('dsn'));
    $containerOptions['charset'] = $install->settings->get('database_charset', 'utf8');
    $containerOptions['collation'] = $install->settings->get('database_collation', 'utf8_general_ci');
    $created = $modx->manager->createSourceContainer($dsnArray, $modx->config['username'], $modx->config['password']);
    if (!$created) {
        $results[] = array('class' => 'failed', 'msg' => '<p class="notok">' . $install->lexicon('db_err_create') . '</p>');
    } else {
        $connected = $modx->connect();
    }
    if ($connected) {
        $results[] = array('class' => 'success', 'msg' => '<p class="ok">' . $install->lexicon('db_created') . '</p>');
    }
}
if ($connected) {
    ob_start();
    $modx->loadClass('modAccess');
开发者ID:DeFi-ManriquezLuis,项目名称:MTLTransfer,代码行数:31,代码来源:tables_create.php


注:本文中的xPDO::parseDSN方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。