Error in php Commands out of sync; you can not run this command now

0

I have already read a few articles, but I can not fix this error that I have. It is the first time I see this error, and I do not know how to solve it. Then using PHP and MYSQL to extract data from the database (use redundancy) and display them in the form of a notification. I'm creating a user notification system, but I had not noticed. The notification system (which is not more than a file notifications.php to extract the data and display them) works correctly on the home page, but not on the profiles or any other page. See.

In this part, notifications work correctly

But in this part, which is the profile of the user, it does not work

This is the PHP code I'm using.

<?php

$notification = $conn->prepare("SELECT n.id_notification, 
                                       n.notification_user, 
                                       n.notification_send_user, 
                                       n.notification_title,
                                       n.notification_datetime,
                                       u.user_image,
                                       u.username
                                       FROM notifications n 
                                       INNER JOIN users u 
                                       ON u.ID = n.notification_send_user
                                       WHERE n.notification_user = ?");

if ($notification) {
    $notification->bind_param("i", $_SESSION["usuario_id"]);
    $notification->execute();
    $notification->store_result();
    $notification->bind_result($id_notification,
                               $notification_user,
                               $notification_send_user,
                               $notification_title,
                               $notification_datetime,
                               $user_image,
                               $username);

    while($notification->fetch()){
        $title = explode(';', $notification_title);

        echo '<li>
                <a href="'.$title[0].'" title="'.$title[1].'" class="list-lyrians__item">
                <img src="'.$user_image.'" alt="">
                <p>
                    '.$title[1].'

                    <span>'.$title[2].'</span>
                    <span class="timeago" title="'.$notification_datetime.'" style="padding-top: 2px;"></span>
                </p>
            </a>
        </li>';
    }

    $notification->close();
} else{
    echo "Ocurrió un error al mostrar las notificaciones" . $conn->error;
}

If you can help me fix this error, I would appreciate it very much.

    
asked by Axel Benitez 04.12.2017 в 05:06
source

1 answer

1

I had the same problem (php 5.6 and MariaDB) and solved it in the following way:

SP:

   SET SESSION group_concat_max_len = 99999999;

    DROP TABLE IF EXISTS DB_cargas.TBL_FACTURAS_CUENTAS_SUSPENSION_PASO;

    CREATE TABLE DB_cargas.TBL_FACTURAS_CUENTAS_SUSPENSION_PASO
    SELECT 
    EMAIL_DESTINATARIO,
    GROUP_CONCAT(DISTINCT MAIL_EDAC ORDER BY MAIL_EDAC ASC) AS MAIL_EDAC,
    MANDANTE,
    SUSPENSION,
    -- SERBANC,
    SUM(MONTO) AS TOTAL, 
    NOMBRE,
    RUT,
    COUNT(RUT) AS N_DOCUMENTOS_VENCIDOS,
    GROUP_CONCAT(CUENTA,'; ',ESTADO_CUENTA,'; ', NRO_FACTURA, '; ', VENCIMIENTO, '; ', EMISION, '; ',MONTO SEPARATOR '; ') as DETALLETT
    FROM DB_cargas.TBL_FACTURAS_CUENTAS_SUSPENSION GROUP BY rut;


    SELECT * from DB_cargas.TBL_FACTURAS_CUENTAS_SUSPENSION_PASO;
<?php

$conexionEscritura = CreaNuevaConexion();

$sqlSP = "CALL MiBase.ProcedimientoAalmacenado();";
$resultado = mysql_query($sqlSP, $conexionEscritura) or die("Error: \n".mysql_error()."\n".$sqlSP);

while($registro = mysql_fetch_array($resultado)){
 .... /*Creacion de titulos para un archivo .csv con 'n' columnas como 'n' facturas de origen como filas*/
}

mysql_free_result($resultado);
mysql_close($conexionEscritura);
unset($resultado,$conexionEscritura);

$conexionEscritura = CreaNuevaConexion();

$sql2 = "SELECT * from DB_cargas.TBL_FACTURAS_CUENTAS_SUSPENSION_PASO;";
$resultado_2 = mysql_query($sql2, $conexionEscritura) or die("Error: \n".mysql_error()."\n".$sql2);

.... /*Creación de la data para un archivo .csv*/

?>

Using the 3 lines the php ran [OK]:

  mysql_free_result($resultado);
    mysql_close($conexionEscritura);
    unset($resultado,$conexionEscritura);

It did not work with:

mysql_free_result($resultado);
mysql_close($conexionEscritura);
    
answered by 14.03.2018 в 17:23