Code has been added to clipboard!

Selecting MySQL Database for MySQLi Procedural Way

Example
<?php
  server = 'server'; 
  $user = 'user'; 
  $pass = 'pass'; 
  $db = 'db';
  // establish connection
  $con = mysqli_connect($server, $user, $pass, $db);
  // see if the connection has been established properly
  if (!$con) {
    die("Failed to connect: " . mysqli_connect_error());
  }
  $sql = "SELECT user_id, name, surname FROM users";
  $result = mysqli_query($con, $sql);
  if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
      // display data from the query
      echo "User Id: " . $row["user_id"]. " - Name: " . $row["name"]. " - Surname: " . $row["surname"]. "<br>"; 
      }
  } else { 
    echo "0 results";
  }
  mysqli_close($con);  
?>