Created
June 25, 2013 05:14
-
-
Save tournasdim/5856099 to your computer and use it in GitHub Desktop.
Mysqli connection example (using OOP)
This file contains 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 = new mysqli("localhost", "my_user", "my_password", "world"); | |
if (mysqli_connect_errno()) | |
{ | |
printf("Connect failed: %s", mysqli_connect_error()); | |
exit(); | |
} | |
$query = "SELECT * FROM users WHERE user_id='$userid'"; | |
if ($result = $mysqli->query($query)) | |
{ | |
while ($row = $result->fetch_assoc()) | |
{ | |
echo $row['name'] ."<br />" ; | |
} | |
$result->close(); | |
} | |
$mysqli->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment