We can use prepared statements to repeatedly execute the same or similar will statements.
The two main benefits to using prepared statements include their ability to prevent against the common
security threat known as ESC fuel injection and also the input data much more efficiently into the database
to illustrate how prepared statements were.
We'll go over an example.
Once you've created this script save it in your HP lessons folder we've named ours prepared not P HP
in our file.
We first start with our database connection.
Next we prepare an Eskimo statement template that is sent to the database with certain values left unspecified
these unspecified parameters are labeled with a question mark is shown here you can see that this statement
would contain three parameters each parameter would be inputted into the columns First Name Last Name
and Email
we can see the list of parameters down here these parameters will define the values to be executed with
our escudos statement.
We have three parameters specified each parameter has three values attached to three variables.
First name last name and email.
In order to bind each of these parameters to our school statement we use the bind param function to
bind perimeter starts with an argument.
SS s which identifies each variable contained in the parameter is a string once we finished executing
the prepared statements we close the statement and the database connection.
Now we can test our script by running it in our web browser
to do so.
Take the You are all to your script in your address bar and press enter.
You should see the message.
New records created displayed in your web browser and to confirm that the records were added in I'll
just refresh the table in my admin.
This is the user's table
and we can see the values have been added.
Lewis Hall.
Alan Moore and Dave Jones is specified in our parameters.