Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


27.3.6.9 PreparedStatement Object

ThePreparedStatement object represents a handler for the execution of a prepared statement. It supports the following methods:

  • bind(Valuedata): Registers a list of one or more values to be bound on the execution of the SQL statement. Parameters are bound in the order listed and are type-specific; seeSection 27.3.4, “JavaScript Stored Program Data Types and Argument Handling”, for a list of supported data types.

    Prior to a prepared statement's initial execution, all its parameters must be bound to values; failing to do so raises an error when the attempting to callPreparedStatement.execute(). Subsequent executions of the prepared statement can be performed using fewer bind parameters than parameter markers in the statement; in this case, themissing parameters retain their values from the previous execution.

    Attempting to bind more parameters than parameter markers or to parameters of incorrect types is rejected with an error. Invoking this method afterdeallocate() has been called for this prepared statement also raises an error.

    Returns a reference to the samePreparedStatement object on which it was invoked.

  • deallocate(): Closes the prepared statement and frees associated resources. NoPreparedStatement orSqlResult method calls should be made after this is done.

    Calling this method is equivalent to executing aDEALLOCATE PREPARE statement in themysql client.

  • execute(): Executes the prepared query and returns the correspondingSqlResult.

    Calling this method is equivalent to running anEXECUTE statement in themysql client.

  • getOption(StringoptionName): get the value of the optionName option for this statement. Only the valuespassResultToClient andcharsetName are supported.

SeeSection 27.3.7.2, “Prepared Statements”, for additional information and examples.