PHP and Mysql How Does It Work?

Learn the basics of how PHP and MySQL can be used together.

What is MySQL?

MySQL is a database software. Its very popular and used A LOT on the internet. Its more likely that the websites out there with huge user databases like facebook more likely use MySQL.

Using them together

We can use PHP and MySQL together which makes a very powerful team. We can create some amazing things using them and you will have some fun trying to making them.

In order to use MySQL we need to use “queries” to get and add data to a database. If you have some web space pretty much all of them will give you a MySQL database.

$query = mysql_query(”SELECT * FROM tableName”);

We can see we have created a simple query that will select all (*) from a table called “tableName” from the database. The * means all if you are wondering. So it reads “SEELCT ALL FROM TABLE tableName”.

$query = mysql_query(”INSERT INTO tableName (’name’,'age’) VALUES (’Dale’,'21′)”);

The query above will insert new data into the database. It will add values to 2 columns one called “name” and one called “age”. It will set the values of them columns as “Dale” and “21″. So there will be one row added to the database with them values.

Name        |        Age
———————————
Dale          |        21

If we add a new row with different information it will look like the following.

Name        |        Age
———————————
Dale          |        21
Bob           |        24

We can keep updating the database until we build up a nice little database. We can of course have more columns to store more information about the user. For instance we could have columns for Location and so on.

We can put this all into PHP easily.

$query = mysql_query(”SELECT * FROM table”);
if($query)
{
    echo “Query successful”;
}

We can make some very interesting things using them. So you can take a look around and see how people make things like blogs and forums. They of course are the harder of the scripts to write, but once you learn PHP and MySQL in more detail. You will be able to make them very easily. You can make some nice scripts and i would suggest learning as much about MySQL (There is not a lot to learn). You can then make some nice scripts and get you on your way.

One Response

09.07.09

Good article. Lion’s share of the websites are built with php and mysql. It is easy and powerful.

Leave Your Response