MySQLi OOP connection example PHP


$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

if (mysqli_connect_errno())
{
   printf("Connect failed: %s\n", 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();
This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>