Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created June 19, 2016 14:39
Show Gist options
  • Select an option

  • Save stevesohcot/f70c5dbbbdfbfcd8b8947ddb29d9bb44 to your computer and use it in GitHub Desktop.

Select an option

Save stevesohcot/f70c5dbbbdfbfcd8b8947ddb29d9bb44 to your computer and use it in GitHub Desktop.
Sample connection to local PHP/MySQL using XAMPP
<h1>Connect to a database</h1>
<?php
// http://stevesohcot.com/tech-lessons-learned/2016/06/19/xampp-php-setup-on-a-mac/
// Sample connection to local PHP/MySQL using XAMPP
$host = "localhost";
$user = "root";
$password = "";
$db1 = mysqli_connect($host, $user, $password, "MyDatabase") or die ("Could not connect");
$query = "SELECT * FROM Users";
$get_entries = mysqli_query($db1, $query);
if ( mysqli_num_rows($get_entries) != 0) {
while ($display_entries = mysqli_fetch_array($get_entries)) {
print "<br>" . $display_entries['username'];
}
}
mysqli_close($db1);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment