Why this PHP error occurs: “Strict standards: mysqli::next_result(): There is no next result set.”?

后端 未结 1 685
青春惊慌失措
青春惊慌失措 2021-01-29 02:21

I have code, which is basically a copy of a php.net\'s code, but for some reason it does not work. Here is the code on php.net:



        
相关标签:
1条回答
  • 2021-01-29 02:57

    Try it with

    } while ($mysqli->more_results() && $mysqli->next_result());
    

    sscce:

    <?php
    ini_set('display_errors', 'on');
    error_reporting(E_ALL|E_STRICT);
    
    $mysqli = new mysqli("localhost", "localonly", "localonly", "test");
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    $mysqli->query('CREATE TEMPORARY TABLE City (ID int auto_increment, `Name` varchar(32), primary key(ID))') or die($mysqli->error);
    
    $stmt = $mysqli->prepare("INSERT INTO City (`Name`) VALUES (?)") or die($mysqli->error);
    $stmt->bind_param('s', $city) or die($stmt->error);
    foreach(range('A','Z') as $c) {
        $city = 'city'.$c;
        $stmt->execute() or die($stmt->error);
    }
    
    $query  = "SELECT CURRENT_USER();";
    $query .= "SELECT Name FROM City ORDER BY ID LIMIT 20, 5";
    
    /* execute multi query */
    if (!$mysqli->multi_query($query)) {
        trigger_error('multi_query failed: '.$mysqli->error, E_USER_ERROR);
    }
    else {
        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->more_results() && $mysqli->next_result());
    }
    

    prints

    'localonly@localhost'
    -----------------
    'cityU'
    'cityV'
    'cityW'
    'cityX'
    'cityY'
    

    without warnings/notices.

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