First, query MySQL database using PHP:
1. The steps to access MySQL via PHP are:
- Connect to MySQL
- Select the Operational database
- Create a field for a query
- The statement that executes the query
- Retrieve the results and display them on the Web page
- Disconnecting from MySQL
We will do these operations in turn, it is important to first create the login details in a secure manner so that others do not have easy access to your database.
2. Create a login file:
Many web sites created in PHP contain several program files that require access to MySQL and require login and password information, so create a separate file to store the information and place it wherever it is needed.
// login.php $db _hostname = ' localhost '; $db _database = ' my_database '; $db _username = ' username '; $db _password = ' password ';? >
3. Connect to the MySQL database:
Now that the login.php file has been created and saved, it can be included in any PHP file that requires access to the data through the require_once statement.
Link MySQL with PHP