/** * Test getConnectedDsn returns a DSN string if it has been set * * @covers Zend\Db\Adapter\Driver\Pdo\Connection::getDsn */ public function testGetDsn() { $dsn = "sqlite::memory:"; $this->connection->setConnectionParameters(array('dsn' => $dsn)); try { $this->connection->connect(); } catch (\Exception $e) { } $responseString = $this->connection->getDsn(); $this->assertEquals($dsn, $responseString); }
/** * @param string $sql * @return Statement */ public function createStatement($sqlOrResource = null) { $statement = clone $this->statementPrototype; if (is_string($sqlOrResource)) { $statement->setSql($sqlOrResource); } elseif ($sqlOrResource instanceof \PDOStatement) { $statement->setResource($sqlOrResource); } $statement->initialize($this->connection->getResource()); return $statement; }
/** * Execute an SQL query * * Displays a more informative exception. * Old one attached as previous exception. * * @param string $sql * @return \Zend\Db\Adapter\Driver\Pdo\Result * @throws InvalidQueryException * @codeCoverageIgnore */ public function execute($sql) { try { return parent::execute($sql); } catch (InvalidQueryException $exception) { throw new InvalidQueryException($exception->getMessage() . ':' . PHP_EOL . $sql, $exception->getCode(), $exception); } }
/** * @return mixed */ public function getLastGeneratedValue() { $this->connection->getLastGeneratedValue(); }
/** * @return mixed */ public function getLastGeneratedValue($name = null) { return $this->connection->getLastGeneratedValue($name); }
/** * Test getResource method tries to connect to the database, it should never return null * * @covers Zend\Db\Adapter\Driver\Pdo\Connection::getResource */ public function testResource() { $this->setExpectedException('Zend\\Db\\Adapter\\Exception\\InvalidConnectionParametersException'); $this->connection->getResource(); }
/** * Extended to set error mode to silent. */ public function connect() { parent::connect(); $this->resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); return $this; }
/** * @group zf3469 */ public function testConnectReturnsConnectionWhenResourceSet() { $resource = new TestAsset\SqliteMemoryPdo(); $connection = new Connection(array()); $connection->setResource($resource); $this->assertSame($connection, $connection->connect()); $connection->disconnect(); unset($connection); unset($resource); }
protected function buildZfAdapter() { $pdoCon = new Db\Adapter\Driver\Pdo\Connection(); $pdoCon->setResource($this->connection->resource()); $pdo = new Db\Adapter\Driver\Pdo\Pdo($pdoCon); $this->adapter = new Db\Adapter\Adapter($pdo); $this->sql = new Db\Sql\Sql($this->adapter); }