How to execute two mysql queries as one in PHP/MYSQL?

前端 未结 8 1001
误落风尘
误落风尘 2020-11-22 13:19

I have two queries, as following:

SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name LIKE \'%prashant%\' LIMIT 0, 10;
SELECT FOUND_ROWS();
<         


        
8条回答
  •  遥遥无期
    2020-11-22 14:05

    Update: Apparently possible by passing a flag to mysql_connect(). See Executing multiple SQL queries in one statement with PHP Nevertheless, any current reader should avoid using the mysql_-class of functions and prefer PDO.

    You can't do that using the regular mysql-api in PHP. Just execute two queries. The second one will be so fast that it won't matter. This is a typical example of micro optimization. Don't worry about it.

    For the record, it can be done using mysqli and the mysqli_multi_query-function.

提交回复
热议问题