How to Query Your MySQL Database Tutorial

Learn how to execute MySQL queries via PHP

If you want to use PHP to query your MySQL database you can do that by either entering the MySQL query command in the PHP script or define the command as a variable and use the variable when needed.

This tutorial explains how to perform the query by using a variable. In that case, the command will look similar to:

The command can be repeated again in the source code. All you need to do is to change the $query variable.

For example, here is the complete code that could be used to create a MySQL table in PHP:

Replace your your_username, your_password and your_database with their actual values in the first three lines of the script.

You can replace the value of the $query variable with any MySQL query you want and you can use the above format to execute it.