Sending a query to MySQL from PHP is as simple as including the relevant SQL inthe query method of a connection object.
Querying a database with mysqli:
<?php
$query = “SELECT * FROM classics”;
$result= $conn->query($query);
if (!$result) die(“Fatal Error”);
?>
As you can see, the MySQL query looks just like what you would type directly at the command line, except that there is no trailing semicolon, as none is needed when you are accessing MySQL from PHP.
Here the variable $query is assigned a string containing the query to be made, and then passed to the query method of the $conn object, which returns a result that we place in the object $result. If $result is FALSE, there was a problem and the error
property of the connection object will contain the details, so the die function is called to display that error.
All the data returned by MySQL is now stored in an easily interrogable format in the $result object.