Create a MySQLi connection


/*
 * Create a MySQLi connection 
 * and fetch data from a table.
 */

// Set host and credentials.
$host = '127.0.0.1';
$database = 'db';
$user = 'user';
$password = 'pass';

// Create and check connection.
$connection = mysqli_connect($host, $user, $password, $database);
if(!$connection)
  exit('Could not establish connection ' . mysqli_connect_error());

// Create a simple query.
$items = $connection->query('SELECT * FROM table');

// See number of items to handle.
print 'Number of items fetched: ' . $items->num_rows;