Multiple SQL Statements in One MySQL Query
Question:
Can multiple SQL statements, such as "UPDATE table SET name = 'bob'" and "UPDATE table SET age = 55 WHERE name = 'jim'", be executed in a single mysql_query() call?
Answer:
While it was previously possible to execute multiple SQL statements in one mysql_query() call, this approach is now discouraged due to potential security risks. As mentioned in the edited part of the question, mysql_* functions like mysql_query are deprecated as of PHP 5.5 and should no longer be used.
Alternative Method:
If you need to execute multiple SQL statements in a single operation, it is recommended to use the mysqli::multi_query method instead. However, it is important to be cautious when using this method, as it can expose your system to SQL injection attacks if not handled properly.
The above is the detailed content of Can Multiple SQL Statements Be Executed in a Single MySQL Query?. For more information, please follow other related articles on the PHP Chinese website!