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

前端 未结 8 831
误落风尘
误落风尘 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 13:49

    You have to use MySQLi, below code works well

    multi_query($query)) {
        do {
            /* store first result set */
            if ($result = $mysqli->store_result()) {
                while ($row = $result->fetch_row()) {
                    printf("%s\n", $row[0]);
                }
                $result->free();
            }
            /* print divider */
            if ($mysqli->more_results()) {
                printf("-----------------\n");
            }
        } while ($mysqli->next_result());
    }
    
    /* close connection */
    $mysqli->close();
    ?>
    

提交回复
热议问题