creole
[ class tree: creole ] [ index: creole ] [ all elements ]

Class: PreparedStatement

Source Location: /creole/PreparedStatement.php

Interface Overview


Interface for a pre-compiled SQL statement.


Author(s):

Version:

  • $Revision: 1.20 $

Methods


Child classes:

CallableStatement
Interface for callable statements.

Class Details

[line 50]
Interface for a pre-compiled SQL statement.

Many drivers do not take advantage of pre-compiling SQL statements; for these cases the precompilation is emulated. This emulation comes with slight penalty involved in parsing the queries, but provides other benefits such as a cleaner object model and ability to work with BLOB and CLOB values w/o needing special LOB-specific routines.

This class is abstract because there are driver-specific implementations in [clearly] how queries are executed, and how parameters are bound.

This class is not as abstract as the JDBC version. For exmple, if you are using a driver that uses name-based query param substitution, then you'd better bind your variables to names rather than index numbers. e.g. in Oracle

  1. $stmt = $conn->prepareStatement("INSERT INTO users (name, passwd) VALUES (:name, :pass)");
  2. $stmt->setString(":name", $name);
  3. $stmt->executeUpdate();

Developer note: In many ways this interface is an extension of the Statement interface. However, due to limitations in PHP5's interface extension model (specifically that you cannot change signatures on methods defined in parent interface), we cannot extend the Statement interface.




Tags:

version:  $Revision: 1.20 $
author:  Hans Lellelid <hans@xmpl.org>


[ Top ]


Class Methods


method close [line 71]

void close( )

Free resources associated with this statement.

Some drivers will need to implement this method to free database result resources.




Tags:

access:  public


[ Top ]

method executeQuery [line 146]

ResultSet executeQuery( [mixed $p1 = null], [int $fetchmode = null])

Executes the SQL query in this PreparedStatement object and returns the resultset generated by the query.

We support two signatures for this method:

  • $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
  • $stmt->executeQuery(array($param1, $param2), ResultSet::FETCHMODE_NUM);




Tags:

access:  public
throws:  SQLException if a database access error occurs.


Parameters:

mixed   $p1   Either (array) Parameters that will be set using PreparedStatement::set() before query is executed or (int) fetchmode.
int   $fetchmode   The mode to use when fetching the results (e.g. ResultSet::FETCHMODE_NUM, ResultSet::FETCHMODE_ASSOC).

[ Top ]

method executeUpdate [line 155]

int executeUpdate( [array $params = null])

Executes the SQL INSERT, UPDATE, or DELETE statement in this PreparedStatement object.



Tags:

return:  Number of affected rows (or 0 for drivers that return nothing).
access:  public
throws:  SQLException if a database access error occurs.


Parameters:

array   $params   Parameters that will be set using PreparedStatement::set() before query is executed.

[ Top ]

method getConnection [line 56]

Connection getConnection( )

Gets the db Connection that created this statement.



Tags:

access:  public


[ Top ]

method getLimit [line 117]

int getLimit( )

Returns the maximum number of rows to return or 0 for all.



Tags:

access:  public


[ Top ]

method getMoreResults [line 95]

boolean getMoreResults( )

Gets next result set (if this behavior is supported by driver).

Some drivers (e.g. MSSQL) support returning multiple result sets -- e.g. from stored procedures.

This function also closes any current restult set.

Default behavior is for this function to return false. Driver-specific implementations of this class can override this method if they actually support multiple result sets.




Tags:

return:  True if there is another result set, otherwise false.
access:  public


[ Top ]

method getOffset [line 134]

int getOffset( )

Returns the start row.

Offset only applies when Limit is set!




Tags:

access:  public


[ Top ]

method getResource [line 62]

resource getResource( )

Get the PHP native resource for the statement (if supported).



Tags:

access:  public


[ Top ]

method getResultSet [line 80]

RestultSet getResultSet( )

Get result set.

This assumes that the last thing done was an executeQuery() or an execute() with SELECT-type query.




Tags:

return:  Last ResultSet or
  1. null
if not applicable.
access:  public


[ Top ]

method getUpdateCount [line 102]

int getUpdateCount( )

Get update count.



Tags:

return:  Number of records affected, or
  1. null
if not applicable.
access:  public


[ Top ]

method set [line 169]

void set( int $paramIndex, mixed $value)

A generic set method.

You can use this if you don't want to concern yourself with the details. It involves slightly more overhead than the specific settesr, since it grabs the PHP type to determine which method makes most sense.




Tags:

access:  public
throws:  SQLException


Parameters:

int   $paramIndex  
mixed   $value  

[ Top ]

method setArray [line 179]

void setArray( int $paramIndex, array $value)

Sets an array.

Unless a driver-specific method is used, this means simply serializing the passed parameter and storing it as a string.




Tags:

access:  public


Parameters:

int   $paramIndex  
array   $value  

[ Top ]

method setBlob [line 196]

void setBlob( int $paramIndex, mixed $blob)



Tags:

access:  public


Parameters:

int   $paramIndex  
mixed   $blob   Blob object or string containing data.

[ Top ]

method setBoolean [line 188]

void setBoolean( int $paramIndex, boolean $value)

Sets a boolean value.

Default behavior is true = 1, false = 0.




Tags:

access:  public


Parameters:

int   $paramIndex  
boolean   $value  

[ Top ]

method setClob [line 203]

void setClob( int $paramIndex, mixed $clob)



Tags:

access:  public


Parameters:

int   $paramIndex  
mixed   $clob   Clob object or string containing data.

[ Top ]

method setDate [line 210]

void setDate( int $paramIndex, string $value)



Tags:

access:  public


Parameters:

int   $paramIndex  
string   $value  

[ Top ]

method setFloat [line 217]

void setFloat( int $paramIndex, float $value)



Tags:

access:  public


Parameters:

int   $paramIndex  
float   $value  

[ Top ]

method setInt [line 224]

void setInt( int $paramIndex, int $value)



Tags:

access:  public


Parameters:

int   $paramIndex  
int   $value  

[ Top ]

method setLimit [line 111]

void setLimit( int $v)

Sets the maximum number of rows to return from db.

This will affect the SQL if the RDBMS supports native LIMIT; if not, it will be emulated. Limit only applies to queries (not update sql).




Tags:

access:  public


Parameters:

int   $v   Maximum number of rows or 0 for all rows.

[ Top ]

method setNull [line 230]

void setNull( int $paramIndex)



Tags:

access:  public


Parameters:

int   $paramIndex  

[ Top ]

method setOffset [line 127]

void setOffset( int $v)

Sets the start row.

This will affect the SQL if the RDBMS supports native OFFSET; if not, it will be emulated. Offset only applies to queries (not update) and only is evaluated when LIMIT is set!




Tags:

access:  public


Parameters:

int   $v  

[ Top ]

method setString [line 237]

void setString( int $paramIndex, string $value)



Tags:

access:  public


Parameters:

int   $paramIndex  
string   $value  

[ Top ]

method setTime [line 244]

void setTime( int $paramIndex, string $value)



Tags:

access:  public


Parameters:

int   $paramIndex  
string   $value  

[ Top ]

method setTimestamp [line 251]

void setTimestamp( int $paramIndex, string $value)



Tags:

access:  public


Parameters:

int   $paramIndex  
string   $value  

[ Top ]


Documentation generated on Mon, 23 Aug 2004 21:52:42 -0400 by phpDocumentor 1.3.0RC3