Skip to content

Instantly share code, notes, and snippets.

@barmgeat
Created December 28, 2020 02:55
Show Gist options
  • Save barmgeat/13d635bb1cec308a67f385f6b244a21f to your computer and use it in GitHub Desktop.
Save barmgeat/13d635bb1cec308a67f385f6b244a21f to your computer and use it in GitHub Desktop.
MySQLi Procedural.php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment