[php-src] Issue #12426: Cannot echo after commit transaction

From: Date: Thu, 12 Oct 2023 16:39:39 +0000
Subject: [php-src] Issue #12426: Cannot echo after commit transaction
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245551@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12426 Author: xhit ### Description The following code: ```php <?php function createChatroom(){ try { global $conexion; $conexion->beginTransaction(); $q = 'INSERT INTO chatroom (bot_id, client_id, conversation_id, department_id, created_at) VALUES (:bot_id, :client_id, :conversation_id, :department_id, UTC_TIMESTAMP(3))'; $stmt = $conexion->prepare($q); $stmt->bindParam(':bot_id', $_SESSION['bot_id'], PDO::PARAM_STR); $stmt->bindParam(':client_id', $_SESSION['client_id'], PDO::PARAM_STR); $stmt->bindParam(':conversation_id', $_POST['conversation_id'], PDO::PARAM_STR); $stmt->bindParam(':department_id', $dept[1], PDO::PARAM_STR); $stmt->execute(); $chatroom_id = $conexion->lastInsertId(); if($conexion->commit()){ $_SESSION['chatroom_id'] = $chatroom_id; $aa = array( 'chatroom_id' => $chatroom_id, 'conversation_id' => $_POST['conversation_id'], ); echo json_encode($aa); //echo "a"; exit; } } catch (\PDOException $e) { // rollback the transaction $conexion->rollBack(); apiResponse::triggerResponse("error creating chatroom", true); } } ``` Resulted in this output: The transaction was committed in the database, but not output But I expected this output instead: ``` {"chatroom_id":"233","conversation_id":"500d2775-f756-4ff1-83b4-f9d861bc4db5"} ``` But if I uncomment the echo "a"; line, the expected output is caught with the suffix a If I exec the query without transaction, it works. ### PHP Version PHP 8.1.24 ### Operating System Ubuntu 22.04

« previous php.bugs (#245551) next »