One of the things about migrating to PHP 7 is that the mysql_
functions have been removed. They had been deprecated since PHP 5.5 but since PHP 7.0, they're gone.
Luckily, mysqli_
functions can offer drop-in replacements for most functions. Usually PDO
is probably preferable but if you're refactoring a large codebase with lots of mysql_
uses already, then it's probably fine to just use mysqli
.
- mysql_affected_rows()
+ mysqli_affected_rows($conn)
- mysql_close($conn)
+ mysqli_close($conn)
- mysql_connect($server, $username, $password)
+ mysqli_connect($server, $username, $password)
- mysql_data_seek($result, $row)
+ mysqli_data_seek($result, $row)
- mysql_errno()
+ mysqli_errno($conn)
- mysql_error()
+ mysqli_error($conn)
+ mysqli_connect_errno()
+ mysqli_connect_error()
- mysql_fetch_array($result)
+ mysqli_fetch_array($result)
- mysql_fetch_assoc($result)
+ mysqli_fetch_assoc($result)
- mysql_fetch_object($result)
+ mysqli_fetch_object($result)
- mysql_free_result($result)
+ mysqli_free_result($result)
- mysql_insert_id()
+ mysqli_insert_id($conn)
- mysql_num_rows()
+ mysqli_num_rows($result)
- mysql_query($sql)
+ mysqli_query($conn, $sql)
- mysql_real_escape_string($string)
+ mysqli_real_escape_string($conn, $string)
- mysql_result($result, $row, $field)
// No alternative
- mysql_select_db($db)
+ mysqli_select_db($conn, $db)