Skip to content

Instantly share code, notes, and snippets.

@pmjones
Created December 4, 2012 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmjones/4199388 to your computer and use it in GitHub Desktop.
Save pmjones/4199388 to your computer and use it in GitHub Desktop.
Aura setPdo() diff
diff --git a/src/Aura/Sql/Connection/AbstractConnection.php b/src/Aura/Sql/Connection/AbstractConnection.php
index 467498c..2dca2a5 100644
--- a/src/Aura/Sql/Connection/AbstractConnection.php
+++ b/src/Aura/Sql/Connection/AbstractConnection.php
@@ -72,6 +72,8 @@ abstract class AbstractConnection
*/
protected $password;
+ protected $profiler;
+
/**
*
* The PDO connection object.
@@ -81,6 +83,8 @@ abstract class AbstractConnection
*/
protected $pdo;
+ protected $query_factory;
+
/**
*
* The prefix to use when quoting identifier names.
@@ -131,7 +135,7 @@ abstract class AbstractConnection
ProfilerInterface $profiler,
ColumnFactory $column_factory,
QueryFactory $query_factory,
- $dsn,
+ $dsn = null,
$username = null,
$password = null,
array $options = []
@@ -207,6 +211,25 @@ abstract class AbstractConnection
/**
*
+ * Sets the PDO connection object; typically used when a shared PDO object
+ * already exists in a legacy context.
+ *
+ * Note that if you use setPdo(), the pre- and post-connect method hooks
+ * will not be called.
+ *
+ * @param PDO $pdo The PDO object.
+ *
+ * @return void
+ *
+ */
+ public function setPdo(PDO $pdo)
+ {
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $this->pdo = $pdo;
+ }
+
+ /**
+ *
* Returns the PDO connection object; if it does not exist, creates it to
* connect to the database.
*
@@ -215,9 +238,7 @@ abstract class AbstractConnection
*/
public function getPdo()
{
- if (! $this->pdo) {
- $this->connect();
- }
+ $this->connect();
return $this->pdo;
}
@@ -230,6 +251,10 @@ abstract class AbstractConnection
*/
public function connect()
{
+ if ($this->pdo) {
+ return;
+ }
+
$this->preConnect();
$this->pdo = $this->newPdo();
$this->postConnect();
diff --git a/src/Aura/Sql/ConnectionFactory.php b/src/Aura/Sql/ConnectionFactory.php
index 30637dd..27ba18d 100644
--- a/src/Aura/Sql/ConnectionFactory.php
+++ b/src/Aura/Sql/ConnectionFactory.php
@@ -65,7 +65,7 @@ class ConnectionFactory
*/
public function newInstance(
$adapter,
- $dsn,
+ $dsn = null,
$username = null,
$password = null,
$options = []
@harikt
Copy link

harikt commented Dec 4, 2012

Why I put the preconnect as is for let it do if it needs to do something else other than the pdo stuffs .

@harikt
Copy link

harikt commented Dec 4, 2012

I don't prefer null for dsn . Reason is auraphp/Aura.Sql#34 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment