Home > Database > Mysql Tutorial > Can Multiple SQL UPDATE Queries Be Executed with a Single `mysqli_multi_query()` Call?

Can Multiple SQL UPDATE Queries Be Executed with a Single `mysqli_multi_query()` Call?

DDD
Release: 2024-12-18 07:15:13
Original
109 people have browsed it

Can Multiple SQL UPDATE Queries Be Executed with a Single `mysqli_multi_query()` Call?

Executing Multiple SQL Statements with mysql_query()

In the realm of MySQL database operations, it may be desirable to execute multiple SQL statements in a single mysql_query() call. The question arises: is it possible to combine update queries within the same mysql_query() function?

Approach

Historically, the mysql_query() function did not support the execution of multiple statements in a single call. However, since the release of PHP 5.5, the mysql_ functions have been deprecated and replaced with mysqli_ functions.

The mysqli::multi_query() function offers the ability to execute multiple SQL statements consecutively. It is important to note that this function should be used with caution, as it potentially increases the vulnerability to SQL injection attacks.

Usage

To execute multiple update statements within mysqli::multi_query(), you can use the following syntax:

mysqli_multi_query($mysqli, "UPDATE table SET name = 'bob'; UPDATE table SET age = 55 WHERE name = 'jim';");
Copy after login

This will execute both update statements in sequence, allowing you to modify multiple rows and columns without the need for separate mysql_query() calls.

The above is the detailed content of Can Multiple SQL UPDATE Queries Be Executed with a Single `mysqli_multi_query()` Call?. 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