-
Notifications
You must be signed in to change notification settings - Fork 2
PreparedStatement
Alexey Borzov edited this page Sep 12, 2017
·
2 revisions
An instance of this class is returned by \sad_spirit\pg_wrapper\Connection::prepare()
. It prepares a query via pg_prepare()
and executes it later using pg_execute()
.
PreparedStatement
has the following public methods:
-
bindParam(int $paramNum, mixed &$param, mixed $type = null): $this
- Binds a variable to a parameter of the prepared query-
$paramNum
- 1-based parameter number -
$param
- Variable to bind -
$type
- either aTypeConverter
instance or a type specification forTypeConverterFactory
. Will be used to convert the parameter when executing the statement.
-
-
bindValue(int $paramNum, mixed $value, mixed $type = null): $this
- Sets the value for a parameter of the prepared query-
$paramNum
- 1-based parameter number -
$value
- Parameter value -
$type
- either aTypeConverter
instance or a type specification forTypeConverterFactory
. Will be used to convert the parameter when executing the statement.
-
-
execute(array $params = array(), array $resultTypes = array()): ResultSet|int
- Executes the prepared query returning either the number of affected rows orResultSet
depending on query-
$params
- Input parameters for query. When provided these will override bound parameters set by above methods. -
$resultTypes
- Types for output columns, will be passed toResultSet
. The array should contain eitherTypeConverter
instances or type specifications forTypeConverterFactory
and its indexes may be either names or indexes of result columns.
-
-
prepare(): $this
- Actually prepares the statement withpg_prepare()
. Automatically called by constructor. -
deallocate(): $this
- Manually deallocates the prepared statement. This is usually not needed as all the prepared statements are automatically deallocated when database connection is closed. Trying to callexecute()
afterdeallocate()
will result in an exception.