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


PHP Creole::parseDSN方法代码示例

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


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

示例1: setDSN

 public static function setDSN($dsn)
 {
     if (is_string($dsn)) {
         $dsn = Creole::parseDSN($dsn);
     }
     self::$dsn = $dsn;
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:7,代码来源:DriverTestManager.php

示例2: addConfig

 public function addConfig()
 {
     if ($this->hasParameter('host')) {
         $this->setParameter('hostspec', $this->getParameter('host'));
     }
     if ($dsn = $this->getParameter('dsn')) {
         require_once 'creole/Creole.php';
         $params = Creole::parseDSN($dsn);
         $options = array('phptype', 'hostspec', 'database', 'username', 'password', 'port', 'protocol', 'encoding', 'persistent', 'socket', 'compat_assoc_lower', 'compat_rtrim_string');
         foreach ($options as $option) {
             if (!$this->getParameter($option) && isset($params[$option])) {
                 $this->setParameter($option, $params[$option]);
             }
         }
     }
     self::$config['propel']['datasources'][$this->getParameter('datasource')] = array('adapter' => $this->getParameter('phptype'), 'connection' => array('phptype' => $this->getParameter('phptype'), 'hostspec' => $this->getParameter('hostspec'), 'database' => $this->getParameter('database'), 'username' => $this->getParameter('username'), 'password' => $this->getParameter('password'), 'port' => $this->getParameter('port'), 'encoding' => $this->getParameter('encoding'), 'persistent' => $this->getParameter('persistent'), 'protocol' => $this->getParameter('protocol'), 'socket' => $this->getParameter('socket'), 'compat_assoc_lower' => $this->getParameter('compat_assoc_lower'), 'compat_rtrim_string' => $this->getParameter('compat_rtrim_string')));
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:17,代码来源:sfPropelDatabase.class.php

示例3: testParseDSN

 /**
  * Test different URL DSNs to make sure they are being parsed correctly.
  */
 public function testParseDSN()
 {
     $dsn = "phptype://username:password@protocol+hostspec:110//usr/db_file.db?param1=value1&param2=value2";
     $dsninfo = Creole::parseDSN($dsn);
     $this->checkDSN($dsninfo, array('phptype', 'username', 'password', 'protocol', 'hostspec', 'port' => 110, 'database' => '/usr/db_file.db', 'param1' => 'value1', 'param2' => 'value2'));
     $dsn = 'phptype://username:password@hostspec/C:\\path\\to\\dbfile.db';
     $this->checkDSN(Creole::parseDSN($dsn), array('phptype', 'username', 'password', 'hostspec', 'database' => 'C:\\path\\to\\dbfile.db'));
     $dsn = "phptype://username:password@hostspec/database";
     $this->checkDSN(Creole::parseDSN($dsn), array('phptype', 'username', 'password', 'hostspec', 'database'));
     $dsn = "phptype://username:password@hostspec";
     $this->checkDSN(Creole::parseDSN($dsn), array('phptype', 'username', 'password', 'hostspec'));
     $dsn = "phptype://username@hostspec";
     $this->checkDSN(Creole::parseDSN($dsn), array('phptype', 'username', 'hostspec'));
     $dsn = "phptype://hostspec/database";
     $this->checkDSN(Creole::parseDSN($dsn), array('phptype', 'hostspec', 'database'));
     $dsn = "phptype";
     $this->checkDSN(Creole::parseDSN($dsn), array('phptype'));
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:21,代码来源:CreoleTest.php

示例4: getConnection

 /**
  * Creates a new Connection as using the driver, url, userid and password specified.
  * The calling method is responsible for closing the connection.
  * @return Connection the newly created connection.
  * @throws BuildException if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
  */
 protected function getConnection()
 {
     if ($this->url === null) {
         throw new BuildException("Url attribute must be set!", $this->location);
     }
     try {
         $this->log("Connecting to " . $this->getUrl(), PROJECT_MSG_VERBOSE);
         $info = new Properties();
         $dsn = Creole::parseDSN($this->url);
         if (!isset($dsn["username"]) && $this->userId === null) {
             throw new BuildException("Username must be in URL or userid attribute must be set.", $this->location);
         }
         if ($this->userId) {
             $dsn["username"] = $this->getUserId();
         }
         if ($this->password) {
             $dsn["password"] = $this->getPassword();
         }
         if ($this->driver) {
             Creole::registerDriver($dsn['phptype'], $this->driver);
         }
         $conn = Creole::getConnection($dsn);
         $conn->setAutoCommit($this->autocommit);
         return $conn;
     } catch (SQLException $e) {
         throw new BuildException($e->getMessage(), $this->location);
     }
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:34,代码来源:CreoleTask.php

示例5: main

 /**
  * Iterates through each datamodel/database, dumps the contents of all tables and creates a DOM XML doc.
  *
  * @return void
  * @throws BuildException
  */
 public function main()
 {
     $this->validate();
     $buf = "Database settings:\n" . " driver: " . ($this->databaseDriver ? $this->databaseDriver : "(default)") . "\n" . " URL: " . $this->databaseUrl . "\n" . ($this->databaseUser ? " user: " . $this->databaseUser . "\n" : "") . ($this->databasePassword ? " password: " . $this->databasePassword . "\n" : "");
     // deprecated
     $this->log($buf, PROJECT_MSG_VERBOSE);
     // 1) First create the Data XML -> database name map.
     $this->createDataDbMap();
     // 2) Now go create the XML files from teh database(s)
     foreach ($this->getDataModels() as $dataModel) {
         // there is really one 1 db per datamodel
         foreach ($dataModel->getDatabases() as $database) {
             // if database name is specified, then we only want to dump that one db.
             if (empty($this->databaseName) || $this->databaseName && $database->getName() == $this->databaseName) {
                 $outFile = $this->getMappedFile($dataModel->getName());
                 $this->log("Dumping data to XML for database: " . $database->getName());
                 $this->log("Writing to XML file: " . $outFile->getName());
                 try {
                     $url = str_replace("@DB@", $database->getName(), $this->databaseUrl);
                     $buf = "Database settings:\n" . " driver: " . ($this->databaseDriver ? $this->databaseDriver : "(default)") . "\n" . " URL: " . $url . "\n" . ($this->databaseUser ? " user: " . $this->databaseUser . "\n" : "") . ($this->databasePassword ? " password: " . $this->databasePassword . "\n" : "");
                     $this->log($buf, PROJECT_MSG_VERBOSE);
                     $dsn = Creole::parseDSN($url);
                     // deprecated, but here for BC
                     if ($this->databaseUser) {
                         $dsn['username'] = $this->databaseUser;
                     }
                     if ($this->databasePassword) {
                         $dsn['password'] = $this->databasePassword;
                     }
                     if ($this->databaseName) {
                         $dsn['database'] = $this->databaseName;
                     }
                     if ($this->databaseDriver) {
                         Creole::registerDriver($dsn['phptype'], $this->databaseDriver);
                     }
                     $this->conn = Creole::getConnection($dsn);
                     $doc = $this->createXMLDoc($database);
                     $doc->save($outFile->getAbsolutePath());
                 } catch (SQLException $se) {
                     $this->log("SQLException while connecting to DB: " . $se->getMessage(), PROJECT_MSG_ERR);
                     throw new BuildException($se);
                 }
             }
             // if databaseName && database->getName == databaseName
         }
         // foreach database
     }
     // foreach datamodel
 }
开发者ID:DBezemer,项目名称:server,代码行数:55,代码来源:PropelDataDumpTask.php

示例6: insertDatabaseSqlFiles

 /**
  * Take the base url, the target database and insert a set of SQL
  * files into the target database.
  *
  * @param      string $url
  * @param      string $database
  * @param      array $transactions
  */
 private function insertDatabaseSqlFiles($url, $database, $transactions)
 {
     $url = str_replace("@DB@", $database, $url);
     $this->log("Our new url -> " . $url);
     try {
         $buf = "Database settings:\n" . " driver: " . ($this->driver ? $this->driver : "(default)") . "\n" . " URL: " . $url . "\n" . ($this->userId ? " user: " . $this->userId . "\n" : "") . ($this->password ? " password: " . $this->password . "\n" : "");
         $this->log($buf, PROJECT_MSG_VERBOSE);
         $dsn = Creole::parseDSN($url);
         if ($this->userId) {
             $dsn["username"] = $this->userId;
         }
         if ($this->password) {
             $dsn["password"] = $this->password;
         }
         if ($this->driver) {
             Creole::registerDriver($dsn['phptype'], $this->driver);
         }
         $this->conn = Creole::getConnection($dsn);
         $this->conn->setAutoCommit($this->autocommit);
         $this->statement = $this->conn->createStatement();
         $out = null;
         try {
             if ($this->output !== null) {
                 $this->log("Opening PrintStream to output file " . $this->output->__toString(), PROJECT_MSG_VERBOSE);
                 $out = new FileWriter($this->output);
             }
             // Process all transactions
             for ($i = 0, $size = count($transactions); $i < $size; $i++) {
                 $transactions[$i]->runTransaction($out);
                 if (!$this->autocommit) {
                     $this->log("Commiting transaction", PROJECT_MSG_VERBOSE);
                     $this->conn->commit();
                 }
             }
         } catch (Exception $e) {
             if ($out) {
                 $out->close();
             }
         }
     } catch (IOException $e) {
         if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
             try {
                 $this->conn->rollback();
             } catch (SQLException $ex) {
                 // do nothing.
                 System::println("Rollback failed.");
             }
         }
         if ($this->statement) {
             $this->statement->close();
         }
         throw new BuildException($e);
     } catch (SQLException $e) {
         if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
             try {
                 $this->conn->rollback();
             } catch (SQLException $ex) {
                 // do nothing.
                 System::println("Rollback failed");
             }
         }
         if ($this->statement) {
             $this->statement->close();
         }
         throw new BuildException($e);
     }
     $this->statement->close();
     $this->log($this->goodSql . " of " . $this->totalSql . " SQL statements executed successfully");
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:77,代码来源:PropelSQLExec.php

示例7: getConnection

 /**
  * Establishes a Creole database connection
  *
  * @return     object The connection
  */
 protected function getConnection()
 {
     // Attemtp to connect to a database.
     $this->dsn = Creole::parseDSN($this->dbUrl);
     if ($this->dbUser) {
         $this->dsn["username"] = $this->dbUser;
     }
     if ($this->dbPassword) {
         $this->dsn["password"] = $this->dbPassword;
     }
     if ($this->dbDriver) {
         Creole::registerDriver($this->dsn['phptype'], $this->dbDriver);
     }
     $con = Creole::getConnection($this->dsn);
     $this->log("DB connection established");
     return $con;
 }
开发者ID:nmicht,项目名称:tlalokes-in-acst,代码行数:22,代码来源:PropelCreoleTransformTask.php


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