Home >Database >Mysql Tutorial >Why Are mysql_* Functions Not Working After PHP Upgrade to 5.5.0?
PHP Upgrade: Unable to Use mysql_* Functions
After upgrading to PHP 5.5.0 from a previous version such as PHP 5.2.0, developers may encounter issues with deprecated mysql_* functions. One common error encountered is:
Deprecated: mysql_real_escape_string()
To resolve this issue, it is recommended to replace deprecated mysql_ functions with their mysqli_ counterparts. For example, mysqli_real_escape_string() should be used instead of mysql_real_escape_string().
However, it is important to note that mysqli_real_escape_string() requires two parameters: a connection variable and the escaping string. When attempting to use mysqli_real_escape_string() with only one argument, the following error may be encountered:
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in
To fix this error, the connection variable must be passed as the first argument. This variable is obtained by establishing a connection to the database using mysqli_connect():
<code class="php">$connection = mysqli_connect("host", "username", "password", "database");</code>
The code example provided can be revised to use mysqli_real_escape_string() correctly:
<code class="php">$username = mysqli_real_escape_string($connection, $username); $password = mysqli_real_escape_string($connection, $password);</code>
It is essential to update PHP knowledge regularly to stay current with the latest best practices and avoid such errors. Alternatively, consider using a database object to connect to the database and handle escaping automatically.
The above is the detailed content of Why Are mysql_* Functions Not Working After PHP Upgrade to 5.5.0?. For more information, please follow other related articles on the PHP Chinese website!