Retrieving data from MySql with PHP is a simple process however you should have the following things set up before implementing this process.
- You Created A Database
- You Granted Privileges to the database
- Created a config.php file to access the database
Code For Retrieving Data From MySql with PHP
<?php include('config.php'); $con = new mysqli("$host", "$username", "$password", "$dbname"); $result = $con->query("SELECT * FROM TABLE") ; while ($row = $result->fetch_assoc()) { echo $row['row-name']; } $con->close(); ?>If you only need one result with PHP and MySQL use this code.
$result = $con->query("SELECT id, mechanic FROM users WHERE id='$var' LIMIT 1") ; $row = $result->fetch_assoc(); echo $row['mechanic'];