Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Created June 25, 2013 05:14
Show Gist options
  • Save tournasdim/5856099 to your computer and use it in GitHub Desktop.
Save tournasdim/5856099 to your computer and use it in GitHub Desktop.
Mysqli connection example (using OOP)
<?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