44
55use PDO ;
66use PDOException ;
7+ use DebugBar \DataCollector \PDO \TraceablePDOStatement ;
78
89/**
910 * A PDO proxy which traces statements
1011 */
1112class TraceablePDO extends PDO
1213{
14+ /** @var PDO */
1315 protected $ pdo ;
1416
17+ /** @var array */
1518 protected $ executedStatements = array ();
1619
1720 public function __construct (PDO $ pdo )
@@ -20,78 +23,177 @@ public function __construct(PDO $pdo)
2023 $ this ->pdo ->setAttribute (PDO ::ATTR_STATEMENT_CLASS , array ('DebugBar\DataCollector\PDO\TraceablePDOStatement ' , array ($ this )));
2124 }
2225
26+ /**
27+ * Initiates a transaction
28+ *
29+ * @link http://php.net/manual/en/pdo.begintransaction.php
30+ * @return bool TRUE on success or FALSE on failure.
31+ */
2332 public function beginTransaction ()
2433 {
2534 return $ this ->pdo ->beginTransaction ();
2635 }
2736
37+ /**
38+ * Commits a transaction
39+ *
40+ * @link http://php.net/manual/en/pdo.commit.php
41+ * @return bool TRUE on success or FALSE on failure.
42+ */
2843 public function commit ()
2944 {
3045 return $ this ->pdo ->commit ();
3146 }
3247
48+ /**
49+ * Fetch extended error information associated with the last operation on the database handle
50+ *
51+ * @link http://php.net/manual/en/pdo.errorinfo.php
52+ * @return array PDO::errorInfo returns an array of error information
53+ */
3354 public function errorCode ()
3455 {
3556 return $ this ->pdo ->errorCode ();
3657 }
3758
59+ /**
60+ * Fetch extended error information associated with the last operation on the database handle
61+ *
62+ * @link http://php.net/manual/en/pdo.errorinfo.php
63+ * @return array PDO::errorInfo returns an array of error information
64+ */
3865 public function errorInfo ()
3966 {
4067 return $ this ->pdo ->errorInfo ();
4168 }
4269
43- public function exec ($ sql )
70+ /**
71+ * Execute an SQL statement and return the number of affected rows
72+ *
73+ * @link http://php.net/manual/en/pdo.exec.php
74+ * @param string $statement
75+ * @return int|bool PDO::exec returns the number of rows that were modified or deleted by the
76+ * SQL statement you issued. If no rows were affected, PDO::exec returns 0. This function may
77+ * return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE.
78+ * Please read the section on Booleans for more information
79+ */
80+ public function exec ($ statement )
4481 {
45- return $ this ->profileCall ('exec ' , $ sql , func_get_args ());
82+ return $ this ->profileCall ('exec ' , $ statement , func_get_args ());
4683 }
4784
48- public function getAttribute ($ attr )
85+ /**
86+ * Retrieve a database connection attribute
87+ *
88+ * @link http://php.net/manual/en/pdo.getattribute.php
89+ * @param int $attribute One of the PDO::ATTR_* constants
90+ * @return mixed A successful call returns the value of the requested PDO attribute.
91+ * An unsuccessful call returns null.
92+ */
93+ public function getAttribute ($ attribute )
4994 {
50- return $ this ->pdo ->getAttribute ($ attr );
95+ return $ this ->pdo ->getAttribute ($ attribute );
5196 }
5297
98+ /**
99+ * Checks if inside a transaction
100+ *
101+ * @link http://php.net/manual/en/pdo.intransaction.php
102+ * @return bool TRUE if a transaction is currently active, and FALSE if not.
103+ */
53104 public function inTransaction ()
54105 {
55106 return $ this ->pdo ->inTransaction ();
56107 }
57108
109+ /**
110+ * Returns the ID of the last inserted row or sequence value
111+ *
112+ * @link http://php.net/manual/en/pdo.lastinsertid.php
113+ * @param string $name [optional]
114+ * @return string If a sequence name was not specified for the name parameter, PDO::lastInsertId
115+ * returns a string representing the row ID of the last row that was inserted into the database.
116+ */
58117 public function lastInsertId ($ name = null )
59118 {
60119 return $ this ->pdo ->lastInsertId ($ name );
61120 }
62121
63- public function prepare ($ sql , $ driver_options = array ())
122+ /**
123+ * Prepares a statement for execution and returns a statement object
124+ *
125+ * @link http://php.net/manual/en/pdo.prepare.php
126+ * @param string $statement This must be a valid SQL statement template for the target DB server.
127+ * @param array $driver_options [optional] This array holds one or more key=>value pairs to
128+ * set attribute values for the PDOStatement object that this method returns.
129+ * @return TraceablePDOStatement|bool If the database server successfully prepares the statement,
130+ * PDO::prepare returns a PDOStatement object. If the database server cannot successfully prepare
131+ * the statement, PDO::prepare returns FALSE or emits PDOException (depending on error handling).
132+ */
133+ public function prepare ($ statement , $ driver_options = array ())
64134 {
65- return $ this ->pdo ->prepare ($ sql , $ driver_options );
135+ return $ this ->pdo ->prepare ($ statement , $ driver_options );
66136 }
67137
68- public function query ($ sql )
138+ /**
139+ * Executes an SQL statement, returning a result set as a PDOStatement object
140+ *
141+ * @link http://php.net/manual/en/pdo.query.php
142+ * @param string $statement
143+ * @return TraceablePDOStatement|bool PDO::query returns a PDOStatement object, or FALSE on
144+ * failure.
145+ */
146+ public function query ($ statement )
69147 {
70- return $ this ->profileCall ('query ' , $ sql , func_get_args ());
148+ return $ this ->profileCall ('query ' , $ statement , func_get_args ());
71149 }
72150
73- public function quote ($ expr , $ parameter_type = PDO ::PARAM_STR )
151+ /**
152+ * Quotes a string for use in a query.
153+ *
154+ * @link http://php.net/manual/en/pdo.quote.php
155+ * @param string $string The string to be quoted.
156+ * @param int $parameter_type [optional] Provides a data type hint for drivers that have
157+ * alternate quoting styles.
158+ * @return string|bool A quoted string that is theoretically safe to pass into an SQL statement.
159+ * Returns FALSE if the driver does not support quoting in this way.
160+ */
161+ public function quote ($ string , $ parameter_type = PDO ::PARAM_STR )
74162 {
75- return $ this ->pdo ->quote ($ expr , $ parameter_type );
163+ return $ this ->pdo ->quote ($ string , $ parameter_type );
76164 }
77165
166+ /**
167+ * Rolls back a transaction
168+ *
169+ * @link http://php.net/manual/en/pdo.rollback.php
170+ * @return bool TRUE on success or FALSE on failure.
171+ */
78172 public function rollBack ()
79173 {
80174 return $ this ->pdo ->rollBack ();
81175 }
82176
83- public function setAttribute ($ attr , $ value )
177+ /**
178+ * Set an attribute
179+ *
180+ * @link http://php.net/manual/en/pdo.setattribute.php
181+ * @param int $attribute
182+ * @param mixed $value
183+ * @return bool TRUE on success or FALSE on failure.
184+ */
185+ public function setAttribute ($ attribute , $ value )
84186 {
85- return $ this ->pdo ->setAttribute ($ attr , $ value );
187+ return $ this ->pdo ->setAttribute ($ attribute , $ value );
86188 }
87189
88190 /**
89191 * Profiles a call to a PDO method
90192 *
91- * @param string $method
92- * @param string $sql
93- * @param array $args
94- * @return mixed The result of the call
193+ * @param string $method
194+ * @param string $sql
195+ * @param array $args
196+ * @return mixed The result of the call
95197 */
96198 protected function profileCall ($ method , $ sql , array $ args )
97199 {
0 commit comments