Home > Database > Mysql Tutorial > Can I Mix mysql_ and mysqli_ APIs in PHP?

Can I Mix mysql_ and mysqli_ APIs in PHP?

DDD
Release: 2024-12-15 03:07:09
Original
311 people have browsed it

Can I Mix mysql_ and mysqli_ APIs in PHP?

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template