diff options
author | xue <> | 2006-11-24 19:15:26 +0000 |
---|---|---|
committer | xue <> | 2006-11-24 19:15:26 +0000 |
commit | 7280a2301a3d3dd251d8302c3f7999fa09780d42 (patch) | |
tree | 4436f61f268a79271ccf7c01fdab7a5be5c50106 /framework | |
parent | 88a073ccbb0026e52d2f83aeeaab4bd9591ef3ab (diff) |
bug fixes of data layer.
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Data/TDbCommand.php | 7 | ||||
-rw-r--r-- | framework/Data/TDbConnection.php | 8 | ||||
-rw-r--r-- | framework/Data/TDbDataReader.php | 6 |
3 files changed, 13 insertions, 8 deletions
diff --git a/framework/Data/TDbCommand.php b/framework/Data/TDbCommand.php index 3d0e367a..df34207c 100644 --- a/framework/Data/TDbCommand.php +++ b/framework/Data/TDbCommand.php @@ -22,6 +22,9 @@ * (such as select), use {@link query} or its convenient versions {@link queryRow}
* and {@link queryScalar}.
*
+ * If an SQL statement returns results (such as a SELECT SQL), the results
+ * can be accessed via the returned {@link TDbDataReader}.
+ *
* TDbCommand supports SQL statment preparation and parameter binding.
* Call {@link bindParameter} to bind a PHP variable to a parameter in SQL.
* Call {@link bindValue} to bind a value to an SQL parameter.
@@ -79,7 +82,7 @@ class TDbCommand extends TComponent /**
* @return PDOStatement the underlying PDOStatement for this command
- * It could be null if the statement is not created yet.
+ * It could be null if the statement is not prepared yet.
*/
public function getPdoStatement()
{
@@ -99,7 +102,7 @@ class TDbCommand extends TComponent {
try
{
- $this->_statement=$this->getConnection()->getPdoInstance()->prepare($sql);
+ $this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText());
}
catch(Exception $e)
{
diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php index cfb4fd72..9ca57a4a 100644 --- a/framework/Data/TDbConnection.php +++ b/framework/Data/TDbConnection.php @@ -20,7 +20,7 @@ Prado::using('System.Data.TDbCommand'); *
* TDbConnection works together with {@link TDbCommand}, {@link TDbDataReader}
* and {@link TDbTransaction} to provide data access to various DBMS
- * in a common set of APIs, thanks to the {@link http://www.php.net/manual/en/ref.pdo.php PDO}
+ * in a common set of APIs. They are a thin wrapper of the {@link http://www.php.net/manual/en/ref.pdo.php PDO}
* PHP extension.
*
* To establish a connection, set {@link setActive Active} to true after
@@ -53,9 +53,9 @@ Prado::using('System.Data.TDbCommand'); *
* To use transaction, do like the following:
* <code>
+ * $transaction=$connection->beginTransaction();
* try
* {
- * $transaction=$connection->beginTransaction();
* $connection->createCommand($sql1)->execute();
* $connection->createCommand($sql2)->execute();
* //.... other SQL executions
@@ -136,8 +136,8 @@ class TDbConnection extends TComponent {
try
{
- $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->_pdo=new PDO($this->getConnectionString(),$this->getUsername(),$this->getPassword(),$this->_attributes);
+ $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->_active=true;
}
catch(PDOException $e)
@@ -454,7 +454,7 @@ class TDbConnection extends TComponent */
public function setAttribute($name,$value)
{
- if($this->getActive())
+ if($this->_pdo instanceof PDO)
$this->_pdo->setAttribute($name,$value);
else
$this->_attributes[$name]=$value;
diff --git a/framework/Data/TDbDataReader.php b/framework/Data/TDbDataReader.php index 32b86c1d..ad3132b0 100644 --- a/framework/Data/TDbDataReader.php +++ b/framework/Data/TDbDataReader.php @@ -18,14 +18,16 @@ * To read the current row of data, call {@link read}. The method {@link readAll}
* returns all the rows in a single array.
*
- * TDbDataReader implements Iterator interface and thus can be used in foreach like the following:
+ * One can also retrieve the rows of data in TDbDataReader by using foreach:
* <code>
* foreach($reader as $row)
* // $row represents a row of data
* </code>
+ * Since TDbDataReader is a forward-only stream, you can only traverse it once.
*
* It is possible to use a specific mode of data fetching by setting
- * {@link setFetchMode FetchMode}. See {@link
+ * {@link setFetchMode FetchMode}. See {@link http://www.php.net/manual/en/function.pdostatement-setfetchmode.php}
+ * for more details.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id $
|