Mysqli doesn't allow multiple queries?

后端 未结 1 321
忘了有多久
忘了有多久 2020-12-22 11:39

I am running a script in PHP that uisng a loop creates a string query for MySQL.

After executing the script I get the following error:

\"You h

相关标签:
1条回答
  • 2020-12-22 12:09

    mysqli allow multiple queries with mysqli_multiple_query function like this:

    $query  = "SELECT CURRENT_USER();";
    $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
    
    /* execute multi query */
    if (mysqli_multi_query($link, $query)) {
        do {
            /* store first result set */
            if ($result = mysqli_store_result($link)) {
                while ($row = mysqli_fetch_row($result)) {
                    printf("%s\n", $row[0]);
                }
                mysqli_free_result($result);
            }
            /* print divider */
            if (mysqli_more_results($link)) {
                printf("-----------------\n");
            }
        } while (mysqli_next_result($link));
    }
    

    note that you need to use semicolon after each query.

    0 讨论(0)
提交回复
热议问题