diff --git a/reference/mysqli/mysqli/prepare.xml b/reference/mysqli/mysqli/prepare.xml
index 62806d2dc5..570503f4db 100644
--- a/reference/mysqli/mysqli/prepare.xml
+++ b/reference/mysqli/mysqli/prepare.xml
@@ -4,7 +4,7 @@
mysqli::prepare
mysqli_prepare
- Prepare an SQL statement for execution
+ Prepares an SQL statement for execution
@@ -25,10 +25,10 @@
operations on the statement. The query must consist of a single SQL statement.
+ The statement template can contain zero or more question mark
+ (?) parameter markers—also called placeholders.
The parameter markers must be bound to application variables using
- mysqli_stmt_bind_param and/or
- mysqli_stmt_bind_result before executing the
- statement or fetching rows.
+ mysqli_stmt_bind_param before executing the statement.
@@ -41,38 +41,30 @@
query
- The query, as a string.
+ The query, as a string. It must consist of a single SQL statement.
-
-
- You should not add a terminating semicolon or \g
- to the statement.
-
-
- This parameter can include one or more parameter markers in the SQL
- statement by embedding question mark (?) characters
+ The SQL statement may contain zero or more parameter markers
+ represented by question mark (?) characters
at the appropriate positions.
+
The markers are legal only in certain places in SQL statements.
- For example, they are allowed in the VALUES()
+ For example, they are permitted in the VALUES()
list of an INSERT statement (to specify column
values for a row), or in a comparison with a column in a
WHERE clause to specify a comparison value.
- However, they are not allowed for identifiers (such as table or
- column names), in the select list that names the columns to be
- returned by a SELECT statement, or to specify both
+ However, they are not permitted for identifiers (such as table or
+ column names), or to specify both
operands of a binary operator such as the = equal
sign. The latter restriction is necessary because it would be
- impossible to determine the parameter type. It's not allowed to
- compare marker with NULL by
- ? IS NULL too. In general, parameters are legal
- only in Data Manipulation Language (DML) statements, and not in Data
- Definition Language (DDL) statements.
+ impossible to determine the parameter type. In general, parameters are
+ legal only in Data Manipulation Language (DML) statements, and not in
+ Data Definition Language (DDL) statements.
@@ -96,80 +88,56 @@
prepare("SELECT District FROM City WHERE Name=?")) {
+$stmt = $mysqli->prepare("SELECT District FROM City WHERE Name=?");
- /* bind parameters for markers */
- $stmt->bind_param("s", $city);
+/* bind parameters for markers */
+$stmt->bind_param("s", $city);
- /* execute query */
- $stmt->execute();
+/* execute query */
+$stmt->execute();
- /* bind result variables */
- $stmt->bind_result($district);
+/* bind result variables */
+$stmt->bind_result($district);
- /* fetch value */
- $stmt->fetch();
+/* fetch value */
+$stmt->fetch();
- printf("%s is in district %s\n", $city, $district);
-
- /* close statement */
- $stmt->close();
-}
-
-/* close connection */
-$mysqli->close();
-?>
+printf("%s is in district %s\n", $city, $district);
]]>
&style.procedural;
+printf("%s is in district %s\n", $city, $district);
]]>
&examples.outputs;
@@ -189,6 +157,7 @@ Amersfoort is in district Utrecht
mysqli_stmt_fetch
mysqli_stmt_bind_param
mysqli_stmt_bind_result
+ mysqli_stmt_get_result
mysqli_stmt_close
diff --git a/reference/mysqli/mysqli_stmt/construct.xml b/reference/mysqli/mysqli_stmt/construct.xml
index fc8d68aaef..c447d931f8 100644
--- a/reference/mysqli/mysqli_stmt/construct.xml
+++ b/reference/mysqli/mysqli_stmt/construct.xml
@@ -23,7 +23,14 @@
&reftitle.parameters;
- &mysqli.link.description;
+
+ link
+
+
+ A valid mysqli object.
+
+
+
query
diff --git a/reference/mysqli/mysqli_stmt/execute.xml b/reference/mysqli/mysqli_stmt/execute.xml
index 6f0eb1407b..dd83e3fda8 100644
--- a/reference/mysqli/mysqli_stmt/execute.xml
+++ b/reference/mysqli/mysqli_stmt/execute.xml
@@ -4,7 +4,7 @@
mysqli_stmt::execute
mysqli_stmt_execute
- Executes a prepared Query
+ Executes a prepared statement
@@ -20,10 +20,11 @@
mysqli_stmtstmt
- Executes a query that has been previously prepared using the
- mysqli_prepare function. When executed any
- parameter markers which exist will automatically be replaced with the
- appropriate data.
+ Executes previously prepared statement. The statement must be successfully
+ prepared prior to execution, using either
+ the mysqli_prepare or
+ mysqli_stmt_prepare function, or by passing the second
+ argument to mysqli_stmt::__construct.
If the statement is UPDATE, DELETE,
@@ -32,13 +33,6 @@
function. Likewise, if the query yields a result set the
mysqli_stmt_fetch function is used.
-
-
- When using mysqli_stmt_execute, the
- mysqli_stmt_fetch function must be used to fetch the
- data prior to performing any additional queries.
-
-
@@ -60,24 +54,21 @@
&reftitle.examples;
- &style.oop;
+ mysqli_stmt::execute example
+ &style.oop;
query("CREATE TABLE myCity LIKE City");
/* Prepare an insert statement */
-$query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)";
-$stmt = $mysqli->prepare($query);
+$stmt = $mysqli->prepare("INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)");
+/* Bind variables to parameters */
$stmt->bind_param("sss", $val1, $val2, $val3);
$val1 = 'Stuttgart';
@@ -94,47 +85,31 @@ $val3 = 'Aquitaine';
/* Execute the statement */
$stmt->execute();
-/* close statement */
-$stmt->close();
-
/* retrieve all rows from myCity */
$query = "SELECT Name, CountryCode, District FROM myCity";
-if ($result = $mysqli->query($query)) {
- while ($row = $result->fetch_row()) {
- printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
- }
- /* free result set */
- $result->close();
+$result = $mysqli->query($query);
+while ($row = $result->fetch_row()) {
+ printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
}
/* remove table */
$mysqli->query("DROP TABLE myCity");
-
-/* close connection */
-$mysqli->close();
-?>
]]>
-
-
- &style.procedural;
+ &style.procedural;
]]>
&examples.outputs;
diff --git a/reference/mysqli/mysqli_stmt/prepare.xml b/reference/mysqli/mysqli_stmt/prepare.xml
index 4c2d49e6cd..ccfdf5d227 100644
--- a/reference/mysqli/mysqli_stmt/prepare.xml
+++ b/reference/mysqli/mysqli_stmt/prepare.xml
@@ -4,14 +4,14 @@
mysqli_stmt::prepare
mysqli_stmt_prepare
- Prepare an SQL statement for execution
+ Prepares an SQL statement for execution
&reftitle.description;
&style.oop;
- public mixedmysqli_stmt::prepare
+ public boolmysqli_stmt::prepare
stringquery
&style.procedural;
@@ -21,13 +21,14 @@
stringquery
- Prepares the SQL query pointed to by the null-terminated string query.
+ Prepares a statement for execution.
+ The query must consist of a single SQL statement.
+ The statement template can contain zero or more question mark
+ (?) parameter markers—also called placeholders.
The parameter markers must be bound to application variables using
- mysqli_stmt_bind_param and/or
- mysqli_stmt_bind_result before executing the
- statement or fetching rows.
+ mysqli_stmt_bind_param before executing the statement.
@@ -75,31 +76,27 @@
The query, as a string. It must consist of a single SQL statement.
- You can include one or more parameter markers in the SQL statement by
- embedding question mark (?) characters at the
- appropriate positions.
+ The SQL statement may contain zero or more parameter markers
+ represented by question mark (?) characters
+ at the appropriate positions.
-
- You should not add a terminating semicolon or \g
- to the statement.
-
-
-
+
The markers are legal only in certain places in SQL statements.
- For example, they are allowed in the VALUES() list of an INSERT statement
- (to specify column values for a row), or in a comparison with a column in
- a WHERE clause to specify a comparison value.
+ For example, they are permitted in the VALUES()
+ list of an INSERT statement (to specify column
+ values for a row), or in a comparison with a column in a
+ WHERE clause to specify a comparison value.
- However, they are not allowed for identifiers (such as table or column names),
- in the select list that names the columns to be returned by a SELECT statement),
- or to specify both operands of a binary operator such as the =
- equal sign. The latter restriction is necessary because it would be impossible
- to determine the parameter type. In general, parameters are legal only in Data
- Manipulation Language (DML) statements, and not in Data Definition Language
- (DDL) statements.
+ However, they are not permitted for identifiers (such as table or
+ column names), or to specify both
+ operands of a binary operator such as the = equal
+ sign. The latter restriction is necessary because it would be
+ impossible to determine the parameter type. In general, parameters are
+ legal only in Data Manipulation Language (DML) statements, and not in
+ Data Definition Language (DDL) statements.
@@ -118,88 +115,63 @@
&reftitle.examples;
- &style.oop;
+ mysqli_stmt::prepare example
+ &style.oop;
stmt_init();
-if ($stmt->prepare("SELECT District FROM City WHERE Name=?")) {
+$stmt = $mysqli->stmt_init();
+$stmt->prepare("SELECT District FROM City WHERE Name=?");
- /* bind parameters for markers */
- $stmt->bind_param("s", $city);
+/* bind parameters for markers */
+$stmt->bind_param("s", $city);
- /* execute query */
- $stmt->execute();
+/* execute query */
+$stmt->execute();
- /* bind result variables */
- $stmt->bind_result($district);
+/* bind result variables */
+$stmt->bind_result($district);
- /* fetch value */
- $stmt->fetch();
+/* fetch value */
+$stmt->fetch();
- printf("%s is in district %s\n", $city, $district);
-
- /* close statement */
- $stmt->close();
-}
-
-/* close connection */
-$mysqli->close();
-?>
+printf("%s is in district %s\n", $city, $district);
]]>
-
-
- &style.procedural;
+ &style.procedural;
+printf("%s is in district %s\n", $city, $district);
]]>
&examples.outputs;