Prepared Statements in Application Programs •Prepared Statements in SQL Scripts •PREPARE, EXECUTE, and DEALLOCATE PREPARE Statements •SQL Syntax Permitted in Prepared Statements Prepared Statements in Application Programs Prepared Statements in SQL Scripts You can use server-side prepared statements through client programming interfaces, including the MySQL C API client library for C programs, MySQL Connector/J for Java programs, and MySQL Connector/NET for programs using .NET technologies. For example, the C API provides a set of function calls that make up its prepared statement API. See C API Prepared Statement Interface. Other language interfaces can provide support for prepared statements that use the binary protocol by linking in the C client library, one example being the  mysqli  extension, available in PHP 5.0 and higher. An alternative SQL interface to prepared statements is available. This interface is not as efficient as using the binary protocol through a prepared statement API, but requires no programming because it is available directly at the SQL level: •You can use it when no programming interface is available to you. •You can use it from any program that can send SQL statements to the server to be executed, such as the  mysql  client program. •You can use it even if the client is using an old version of the client library. •To test how prepared statements work in your application before coding it. •To use prepared statements when you do not have access to a programming API that supports them. •To interactively troubleshoot application issues with prepared statements. •To create a test case that reproduces a problem with prepared statements, so that you can file a bug report. SQL syntax for prepared statements is intended to be used for situations such as these: SQL syntax for prepared statements is based on three SQL statements: PREPARE, EXECUTE, and DEALLOCATE PREPARE Statements The following examples show two equivalent ways of preparing a statement that computes the hypotenuse of a triangle given the lengths of the two sides. The first example shows how to create a prepared statement by using a string literal to supply the text of the statement: mysql>  PREPARE stmt1 FROM ’SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse’; mysql>  SET @a = 3; • PREPARE  prepares a statement for execution (see Section 13.5.1, “PREPARE Statement” ). • EXECUTE  executes a prepared statement (see Section 13.5.2, “EXECUTE Statement” ). • DEALLOCATE PREPARE  releases a prepared statement (see Section 13.5.3, “DEALLOCATE PREPARE Statement” ). 2790