Up to this point we've learned how to administer a my school database through p p my admin we know how
to create a database and insert update and delete records through the graphical user interface.
We also know how to execute some basic Eskew statements through the P HP might been Eskimo ed in this
lesson we'll learn how to embed Eskimo statements in P HP scripts.
Remember the idea is to create dynamic database driven HP sites.
This means we need to be able to do things like retrieve insert update and delete records directly from
our HP scripts depending on our websites interactions with its users we'll start by creating a script
that connects to the Mind website database we created in HP my admin the script will also retrieve an
output the data in the database using the ESC You WILL SELECT statement.
There are two methods we can use that facilitate the connection and communication with our my astral
database.
This includes PTO and my as well.
I for the purpose of these lessons will be using my S2 will I because it was specifically designed for
the my S2 all database it's easier to learn and off and also offers greater speed and compatibility
with my SDL database video on the other hand is more advantageous.
If you think you may switch your web application to another database in the future it's compatible with
over 18 databases.
It's also more challenging to learn in something you should evolve into.
Once you become more proficient with coding and database development to connect to our database using
my as well I enter the following block of code inside your text editor
remember to save this file in the HP lessons folder that we've been using up to this point.
You can assign it any file name we've named hours connect dot HP.
Now let's go through each line of code for a better understanding.
The first thing we need to do is set up three variables the server named variable store is the name
of our host.
Since we're hosting the database on our own computer using the lamp or map server we set our host to
local host
next.
We set up variables called user name and password the values for these variables depends on which user
you'll be using to connect to the database.
Earlier in this section of the course we explored creating users and user privileges using HP.
My admin will be connecting to our database is the root user so you'll need to enter root is the user
name set the password to the one you specified in P HP my admin earlier.
Next we enter the my will I syntax for establishing a new connection to the database.
The connection string is followed by an if statement that checks to see if the connection was successful
if the connection was unsuccessful.
An error message will automatically be displayed.
Lastly we placed an echo statement that will display a message connected successfully.
If there is no connection issues to make sure your connection was established open your web browser
and load the web page using your local host your url.
So we're on the local host our connect P HP file is stored in the HP lessons folder.
So if you've saved your file in the same folder and on the local host log in the same you know once
you do that the page should load and the message connected successfully should be displayed.
If you have any connection issues make sure that your warm server is up and running.
Remember which icon should be green also make sure that you haven't put any typos in the post user name
or password.
If all that checks out you shouldn't have a mission.