0

今天我升级到php8.1,从那以后我遇到了以下问题。我运行以下查询:

$xx1 = sqlsrv_query($db, "SELECT * FROM xx WHERE xx = ".$xy." ORDER BY xx;", array(), array("QueryTimeout" => 30));

然后我想遍历数组并输出数据:

while($xx = sqlsrv_fetch_array($xx1, 2)){
   do something
 }

到目前为止,这一直有效(php7.2)。自从升级以来,不幸的是,这只有时有效。有时它运行没有问题,有时我在日志中收到以下错误:

PHP Fatal error: Uncaught TypeError: sqlsrv_fetch_array(): Argument #1 ($stmt) must be of type resource, bool given in /var/www/xxx.php:30\nStack trace:\n#0 /var/www/xxx.php(30): sqlsrv_fetch_array()\n#1 {main}\n thrown in /var/www/xxx.php on line 30

平均而言,我每执行 5 次就会收到一次错误。

作为requestet完整的代码:

$chatID = $obj['chatID'];

$messages1 = sqlsrv_query($db, "SELECT * FROM dbo.Messages WHERE ChatID = ".$chatID." ORDER BY Date;", array(), array("QueryTimeout" => 30));
if( $messages1 === false ) {
    if( ($errors = sqlsrv_errors() ) != null) {
        foreach( $errors as $error ) {
            console_error("SQLSTATE: ".$error[ 'SQLSTATE']);
            console_error("code: ".$error[ 'code']);
            console_error("message: ".$error[ 'message']);
        }
    }
}
$messagesarray = array();

while($messages = sqlsrv_fetch_array($messages1, 2)){
      array_push($messagesarray, array(
        "messages" =>  $messages['Message'],
        "Date" => $messages['Date']->format('d.m. H:i'),
      );
}
4

0 回答 0