Correct way to connect db
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("127.0.0.1", "db_user", "db_pass", "db_name",3306);
$result = $mysqli->query("SELECT somefield1, somefield2 FROM sometable ORDER BY ID LIMIT 3");
/* Close the connection as soon as it becomes unnecessary */
$mysqli->close();
foreach ($result as $row) {
/* Processing data received from the database */
echo var_dump ($row);
}