Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Connecting PHP to MySQL and output data stored in rows from a table
$db = mysqli_connect('localhost','root','root','database_name')
or die('Error connecting to MySQL server.');
<h1>PHP connecting to MySQL</h1>
$query = "SELECT * FROM table_name";
mysqli_query($db, $query) or die('Error querying database.');
$result = mysqli_query($db, $query);
while ($row = mysqli_fetch_array($result)) {
echo $row['FirstName'] . ' ' . $row['LastName'] . ': ' . $row['Email'] . ' ' . $row['City'] .'<br />';
//Step 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment