(FYI: this example assumes you know some basic SQL)
There are three main ways that you connect to a MySQL database using PHP: the original MySQL extension (function based), MySQL Improved (MySQLi – Object-oriented) and PHP Data Objects (PDO, Object-oriented). This little piece will be about using MySQLi to insert, update and get data from a MySQL database.
Connecting to the database
To connect to a database, we have to create a “link” that we will pass all of our queries through later on. So, to start all we need is:
The $connection variable will become our “link” to the database from now on. We’ll use it to pass through all of our queries. Within the mysqli_connect function, you’ll have to replace the appropriate string with the MySQL host, the database user’s username and password and the database you’ll be accessing.read more