Home > Backend Development > PHP Tutorial > Can I Mix `mysql_` and `mysqli_` APIs in PHP?

Can I Mix `mysql_` and `mysqli_` APIs in PHP?

Barbara Streisand
Release: 2024-12-24 17:17:18
Original
468 people have browsed it

Can I Mix `mysql_` and `mysqli_` APIs in PHP?

Can't Mix MySQL APIs in PHP

Can you mix MySQL APIs in PHP? This question has prompted discussion online, with some claiming it's possible to use both mysql_ and mysqli_ APIs simultaneously. Let's dive into the issue and explore the limitations:

In one example provided, the code appears to connect using mysqli_connect() and close the connection using mysql_close(), raising a warning. This is because these APIs utilize distinct resources incompatible with each other.

In another attempt, mysqli_close() was used, but the warning persisted.

Key Points:

  • You cannot use both mysql_ and mysqli_ APIs simultaneously.
  • Each API creates its own resources, and these resources are incompatible with each other.
  • The correct way to close a mysqli connection is using mysqli_close().

To verify a connection's validity, you can use if (mysqli_connect_errno($con)) { ... } to check for connection errors.

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template