Created
June 19, 2016 14:39
-
-
Save stevesohcot/f70c5dbbbdfbfcd8b8947ddb29d9bb44 to your computer and use it in GitHub Desktop.
Sample connection to local PHP/MySQL using XAMPP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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