Database Reference
In-Depth Information
$sth-> execute ();
$sth-> bind_result ($common_name, $scientific_name);
while ( $sth-> fetch () ) {
print " $common_name - <i> $scientific_name </i> <br/>" ;
}
$sth-> close ();
$connect-> close ();
?>
The first piece of this creates a variable ( $sql_stmnt ) containing the SQL statement we
want to execute. We then prepare that statement withthe prepare() function in relation
to $connect , thus creating a statement handle ( $sth ).
A user would execute the program we're creating through a query at the end of the web
address. For instance, they would add?birdname=Avocetto the web address to query for
a list of Avocet birds.
A WEB FORM
A web user wouldn'tnormally enter a variable name and a search value at the end of a web address in a
web browser. Instead, this web page we're building would be preceded by another web page containing
an HTML form for the user to enter a search parameter. Here's how that web form would look:
<h3>Search Birds Database</h3>
<form action="birds.html" method="post">
<p>Enter a parameter by which to search
the common names of birds in our database:</p>
<input type="text" name="birdname" />
<input type="submit" />
</form>
This form on the preceding page calls the web page we're writing, passing the search parameter to it in
the proper format.
In the next pair of lines in the example, we're capturing the query request value in a vari-
able we named $search_parameter . Because we intend to use this variable with a
LIKE operator, we need to put the % wildcard before and after the variable.
The next lineuses bind_param() to bind the prepared statement to the
$search_parameter , specifying first that it's a string value with the 's' . Then we
use the execute() function toexecute the completed statement handle.
Search WWH ::




Custom Search