Code has been added to clipboard!

Specific MySQL Database for Object-Oriented

Example
<?php
  $server = 'server';
  $user = 'user';
  $pass = 'pass';
  $db = 'db';
  // establish connection
  $con = new mysqli($server, $user, $pass, $db);
  // see if the connection has been established properly
  if ($con->connect_error) {
    die("Failed to connect: " . $conn->connect_error);
  }
  $sql = "SELECT user_id, name, surname FROM users";
  $result = $con->query($sql);
  if ($result->num_rows > 0) {
    echo "<table><tr><th>User Id</th><th>Name</th></tr>";
    while ($row = $result->fetch_assoc()) {
      // display data from the query
      echo "<tr><td>".$row["user_id"]."</td><td>".$row["name"]." ".$row["surname"]."</td></tr>";
    }
    echo "</table>";
  } else {
    echo "0 results";
  }
  $con->close();  
?>