Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/db-clean' of github.com:ralphschindler/zf2 into…
Browse files Browse the repository at this point in the history
… feature/db-clean

Conflicts:
	library/Zend/Db/Adapter/ParameterContainer.php
  • Loading branch information
Ralph Schindler committed Mar 2, 2012
2 parents 4820774 + 3160d36 commit 7d1b1b4
Show file tree
Hide file tree
Showing 35 changed files with 2,068 additions and 279 deletions.
7 changes: 7 additions & 0 deletions library/Zend/Db/Adapter/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ public function query($sql, $parametersOrQueryMode = self::QUERY_MODE_PREPARE)
return $result;
}

/**
* Create statement
*
* @param string $initialSql
* @param ParameterContainerInterface $initialParameters
* @return Driver\StatementInterface
*/
public function createStatement($initialSql = null, $initialParameters = null)
{
$statement = $this->driver->createStatement($initialSql);
Expand Down
84 changes: 79 additions & 5 deletions library/Zend/Db/Adapter/Driver/Mysqli/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,30 @@ class Connection implements ConnectionInterface
* @var Mysqli
*/
protected $driver = null;

/**
* Connection paramters
*
* @var array
*/
protected $connectionParameters = array();

/**
* @var \mysqli
*/
protected $resource = null;

/**
* In transcaction
*
* @var boolean
*/
protected $inTransaction = false;

/**
* Constructor
*
* @param mysqli $connectionInfo
*/
public function __construct($connectionInfo = null)
{
if (is_array($connectionInfo)) {
Expand All @@ -65,22 +79,42 @@ public function setDriver(Mysqli $driver)
return $this;
}

/**
* Set connection parameters
*
* @param array $connectionParameters
* @return Connection
*/
public function setConnectionParameters(array $connectionParameters)
{
$this->connectionParameters = $connectionParameters;
return $this;
}

/**
* Get connection parameters
*
* @return array
*/
public function getConnectionParameters()
{
return $this->connectionParameters;
}

/**
* Get default catalog
*
* @return null
*/
public function getDefaultCatalog()
{
return null;
}

/**
* Get default schema
*
* @return string
*/
public function getDefaultSchema()
{
if (!$this->isConnected()) {
Expand All @@ -93,21 +127,33 @@ public function getDefaultSchema()
return $r[0];
}

/**
* Set resource
*
* @param mysqli $resource
* @return Connection
*/
public function setResource(mysqli $resource)
{
$this->resource = $resource;
return $this;
}

/**
* Get resource
*
* @return \mysqli
*/
public function getResource()
{
$this->connect();
return $this->resource;
}

/**
* Connect
*
* @return null
*/
public function connect()
{
if ($this->resource instanceof \mysqli) {
Expand Down Expand Up @@ -146,11 +192,19 @@ public function connect()

}

/**
* Is connected
*
* @return boolean
*/
public function isConnected()
{
return ($this->resource instanceof \Mysqli);
}

/**
* Disconnect
*/
public function disconnect()
{
if ($this->resource instanceof \PDO) {
Expand All @@ -159,12 +213,18 @@ public function disconnect()
unset($this->resource);
}

/**
* Begin transaction
*/
public function beginTransaction()
{
$this->resource->autocommit(false);
$this->inTransaction = true;
}

/**
* Commit
*/
public function commit()
{
if (!$this->resource) {
Expand All @@ -176,6 +236,11 @@ public function commit()
$this->inTransaction = false;
}

/**
* Rollback
*
* @return Connection
*/
public function rollback()
{
if (!$this->resource) {
Expand All @@ -190,7 +255,12 @@ public function rollback()
return $this;
}


/**
* Execute
*
* @param string $sql
* @return Result
*/
public function execute($sql)
{
if (!$this->isConnected()) {
Expand All @@ -207,7 +277,11 @@ public function execute($sql)
$resultPrototype = $this->driver->createResult(($resultResource === true) ? $this->resource : $resultResource);
return $resultPrototype;
}

/**
* Get last generated id
*
* @return integer
*/
public function getLastGeneratedId()
{
return $this->resource->insert_id;
Expand Down
25 changes: 25 additions & 0 deletions library/Zend/Db/Adapter/Driver/Mysqli/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,46 @@ public function __construct($connection, Statement $statementPrototype = null, R
$this->registerResultPrototype(($resultPrototype) ?: new Result());
}

/**
* Register connection
*
* @param Connection $connection
* @return Mysqli
*/
public function registerConnection(Connection $connection)
{
$this->connection = $connection;
$this->connection->setDriver($this); // needs access to driver to createStatement()
return $this;
}

/**
* Register statement prototype
*
* @param Statement $statementPrototype
*/
public function registerStatementPrototype(Statement $statementPrototype)
{
$this->statementPrototype = $statementPrototype;
$this->statementPrototype->setDriver($this); // needs access to driver to createResult()
}

/**
* Register result prototype
*
* @param Result $resultPrototype
*/
public function registerResultPrototype(Result $resultPrototype)
{
$this->resultPrototype = $resultPrototype;
}

/**
* Get database platform name
*
* @param string $nameFormat
* @return string
*/
public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCASE)
{
if ($nameFormat == self::NAME_FORMAT_CAMELCASE) {
Expand All @@ -96,6 +118,9 @@ public function getDatabasePlatformName($nameFormat = self::NAME_FORMAT_CAMELCAS
}
}

/**
* Check environment
*/
public function checkEnvironment()
{
if (!extension_loaded('mysqli')) {
Expand Down
Loading

0 comments on commit 7d1b1b4

Please sign in to comment.