I'm learning PHP. I've seen these two approaches to connecting to a MySQL database.
Could someone explain what's the difference between them, and why the second approach doesn't work in a standard form submission (is there a syntax error I have missed)?
Approach 1 (works):
$mysqli = new mysqli("$mysql_server", "$mysql_user", "$mysql_pw", "$mysql_db");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
Approach 2 (throws a server error):
$link = mysqli_connect("$mysql_server", "$mysql_user", "$mysql_pw", "$mysql_db");
if (!$link) {
die('Could not connect: ' . mysql_error());
}