-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added mysqli driver. #72
Changes from 1 commit
ed58456
88d1634
208dd75
00adfbd
b8ccef9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/* | ||
* $Id$ | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli; | ||
|
||
use Doctrine\DBAL\Driver as DriverInterface; | ||
|
||
/** | ||
* @author Kim Hensø Rasmussen <[email protected]> | ||
*/ | ||
class Driver implements DriverInterface | ||
{ | ||
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) | ||
{ | ||
return new MysqliConnection($params, $username, $password, $driverOptions); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'mysqli'; | ||
} | ||
|
||
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) | ||
{ | ||
return new \Doctrine\DBAL\Schema\MySqlSchemaManager($conn); | ||
} | ||
|
||
public function getDatabasePlatform() | ||
{ | ||
return new \Doctrine\DBAL\Platforms\MySqlPlatform(); | ||
} | ||
|
||
public function getDatabase(\Doctrine\DBAL\Connection $conn) | ||
{ | ||
$params = $conn->getParams(); | ||
return $params['dbname']; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/* | ||
* $Id$ | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli; | ||
|
||
use Doctrine\DBAL\Driver\Connection as ConnectionInterface; | ||
|
||
/** | ||
* @author Kim Hensø Rasmussen <[email protected]> | ||
*/ | ||
class MysqliConnection implements ConnectionInterface | ||
{ | ||
/** | ||
* @var \mysqli | ||
*/ | ||
private $_conn; | ||
|
||
public function __construct(array $params, $username, $password, array $driverOptions = array()) | ||
{ | ||
$port = isset($params['port']) ? $params['port'] : ini_get('mysqli.default_port'); | ||
$socket = isset($params['unix_socket']) ? $params['unix_socket'] : ini_get('mysqli.default_socket'); | ||
|
||
$this->_conn = new \mysqli($params['host'], $username, $password, $params['dbname'], $port, $socket); | ||
|
||
if (isset($params['charset'])) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this curly brace should be on the previous line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, i fix these, though i got them all before i did the PR.. staring blind. |
||
$this->_conn->set_charset($params['charset']); | ||
} | ||
} | ||
|
||
public function prepare($prepareString) | ||
{ | ||
return new MysqliStatement($this->_conn, $prepareString); | ||
} | ||
|
||
public function query() | ||
{ | ||
$args = func_get_args(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the interface. I dont know why the interface was made so. If you look in the OCI8 and DB2 they do the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @beberlei what is the reason to have an interface without any parameters when all implementations actually accept one ? This seems not clean |
||
$sql = $args[0]; | ||
$stmt = $this->prepare($sql); | ||
$stmt->execute(); | ||
return $stmt; | ||
} | ||
|
||
public function quote($input, $type=\PDO::PARAM_STR) | ||
{ | ||
return "'". $this->_conn->escape_string($input) ."'"; | ||
} | ||
|
||
public function exec($statement) | ||
{ | ||
$this->_conn->query($statement); | ||
return $this->_conn->affected_rows; | ||
} | ||
|
||
public function lastInsertId($name = null) | ||
{ | ||
return $this->_conn->insert_id; | ||
} | ||
|
||
public function beginTransaction() | ||
{ | ||
$this->_conn->query('START TRANSACTION'); | ||
return true; | ||
} | ||
|
||
public function commit() | ||
{ | ||
return $this->_conn->commit(); | ||
} | ||
|
||
public function rollBack() | ||
{ | ||
return $this->_conn->rollback(); | ||
} | ||
|
||
public function errorCode() | ||
{ | ||
return $this->_conn->errno; | ||
} | ||
|
||
public function errorInfo() | ||
{ | ||
return $this->_conn->error; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/* | ||
* $Id$ | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\DBAL\Driver\Mysqli; | ||
|
||
/** | ||
* @author Kim Hensø Rasmussen <[email protected]> | ||
*/ | ||
class MysqliException extends \Exception | ||
{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is a leftt-over from the SVN legacy. You should not include it in new files.