Last active
August 29, 2015 14:17
-
-
Save philsinatra/df78b01b812443929023 to your computer and use it in GitHub Desktop.
Connect to MySQL database via the mysqli command
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
<?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