Skip to content

Instantly share code, notes, and snippets.

@philsinatra
Last active August 29, 2015 14:17
Show Gist options
  • Save philsinatra/df78b01b812443929023 to your computer and use it in GitHub Desktop.
Save philsinatra/df78b01b812443929023 to your computer and use it in GitHub Desktop.
Connect to MySQL database via the mysqli command
<?php
$mysqli = mysqli_connect('host', 'username', 'password', 'database');
if (mysqli_connect_errno($mysqli)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$res = mysqli_query($mysqli, "SELECT id FROM tablename");
$row = mysqli_fetch_assoc($res);
while ($row = $res->fetch_assoc()) {
echo 'id = ' . $row['id'] . "\n";
}
# Reset the internal result pointer
// $res->data_seek(0);
// http://php.net/manual/en/book.mysqli.php
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment