Example #1
0
 /**
  * Tests parsing a DSN with URI invocation
  */
 public function testParseDsnUriInvocation()
 {
     // Set up the file
     $tmpFile = tempnam(sys_get_temp_dir(), 'pdo');
     $dsn = "uri:file://{$tmpFile}";
     file_put_contents($tmpFile, $this->_dsn);
     $parsedDsn = Pdo_Util::parseDsn($dsn, ['dbname', 'charset']);
     $this->assertType('array', $parsedDsn);
     $this->assertArrayHasKey('dbname', $parsedDsn);
     $this->assertArrayHasKey('charset', $parsedDsn);
     $this->assertEquals($this->_dbname, $parsedDsn['dbname']);
     $this->assertEquals($this->_charset, $parsedDsn['charset']);
     unlink($tmpFile);
 }
Example #2
0
 /**
  * Constructor
  *
  * @param string $dsn
  * @param string $username
  * @param string $passwd
  * @param array $options
  * @return void
  */
 public function __construct($dsn, $username = null, $password = null, array $options = array())
 {
     $parsedDsn = Pdo_Util::parseDsn($dsn, array('dbname', 'charset'));
     if (isset($options[PDO::ATTR_PERSISTENT]) && $options[PDO::ATTR_PERSISTENT]) {
         $this->_dbh = @oci_pconnect($username, $password, $parsedDsn['dbname'], $parsedDsn['charset']);
     } else {
         $this->_dbh = @oci_connect($username, $password, $parsedDsn['dbname'], $parsedDsn['charset']);
     }
     if (!$this->_dbh) {
         $e = oci_error();
         throw new PDOException($e['message']);
     }
     $this->_options = $options;
 }