What is PHP and what is MySQL?

So in previous posts I’ve covered the “Front-End” technologies, which present information to a user, but the real powerhouse behind the web, are the “Back-End” technologies, amongst the most popular of which are PHP and MySQL. I’m putting these both in one post, as they go closely hand in hand, working together closely.

PHP, originally stood for Personal Home Page, but now it is just a name in itself. And it is a scripting language that runs on web servers putting together the web pages, before they are sent to the user.

A scripting language differs from other programming languages, in that it generally runs through from the beginning to the end like a script, rather than running until you quit it, like other computer programs. Due to this, PHP scripts will generally have a execution time, so that they abort if they’re running too long, as users won’t want to wait forever to see the web page they’ve asked for.

So, in the post about HTML, I went through how a web page is made from text formatted using HTML, in a very similar fashion to a text document. However, if you’ve used the web for any amount of time, you’ll have noticed that certain web pages appear different to different people, and different whenever you view them. So when you log into facebook, you get all your friends posts and cat videos, but everyone else gets their own friends posts and cat videos.

This is done on the server, where the web page you see is only the result of code that puts it together from bits. The code reads your log in information, detecting who you are, and then looks to see your facebook friends, then goes through their posts adding them to the page that is served to you. It reads all this information from a database.

PHP is the code that runs on the server, running from the beginning of it’s script to the end, sometimes loading other PHP files to add functionality as it is required.

Now while PHP is the language used to build the pages, a lot of the hard work comes from the database, which is commonly MySQL

MySQL (Structured Query Language) is a database system used to store, organise and retrieve information quickly, and much of the data on the internet will be stored in a database. SQL is a language which allows you to retrieve data from the database, usually by using the command SELECT.

Selecting data is generally in the format of

SELECT {data} FROM {database} WHERE {something}.

So, in the above example for Facebook, when the site is building the page with your friends posts, it will first ask the database for a list of your friends, using something along the lines of

SELECT "friends" FROM "friendsdatabase" WHERE "friend"="currentuser";

So it would look for all the friends connected with you.

It would then do something like

SELECT "posts" FROM "postsdatabase" WHERE "user"="friends";

So get all the posts by users in your friends list.

Obviously I’m skipping over the exact details here, but hopefully that gives you a basic idea of how data is recovered from a database.

MySQL also has tools for manipulating the data within the database, and updating it and changing it.

By using MySQL to retrieve the data from a database, then PHP to format that data and build the custom page for each user, is how most of the pages on the internet are built, and pages such as Google, Webmail, Facebook, etc are constructed from thousands of database entries, and presented to you with just the information you need to see.

binary-code-2

Leave a Reply

Your email address will not be published. Required fields are marked *