Mixing MySQL APIs in PHP
Can one intermix the mysql_ and mysqli_ APIs in PHP?
Answer
No, it is not possible to mix the mysql_ and mysqli_ APIs in PHP. These are separate APIs, and the resources they generate are incompatible.
In the provided code examples, the issue is caused by attempting to use mysql_close() to close a mysqli_ connection (or vice versa). This will result in a warning because the two APIs handle connections differently.
To close a mysqli_ connection, one should use mysqli_close(), while for a mysql_ connection one should use mysql_close().
Checking Connection Validity
To check if a MySQL connection is valid, one can use either mysqli_connect_errno() (for mysqli_ connections) or mysql_errno() (for mysql_ connections). These functions return an error code if the connection failed, or 0 if the connection is valid.
The above is the detailed content of Can I Mix mysql_ and mysqli_ APIs in PHP?. For more information, please follow other related articles on the PHP Chinese website!