PHP пытается начатьTransaction () с MySQL просто останавливает код - PullRequest
0 голосов
/ 20 марта 2019

Работал следующий скрипт без сбоев.

Как только я заменил запрос транзакцией>

$ conn-> beginTransaction (); вместо $ conn-> query ();

Кажется, что это просто остановилось, без дополнительной информации.Запросы работают нормально на phpmyadmin ... Есть идеи?

<?php


//Chequear Cliente Inexistente
$sql = 'SELECT * FROM `ip_clients`
            WHERE client_name = "' . $nombre . '"'; // Collation es _ci
if ($result = $conn->query($sql)) {
    echo "Query: " . $sql . "<br>";
    /* determinar el número de filas del resultado */
    $row_cnt = $result->num_rows;

    if ($row_cnt > 0)
    {
        exit('Ya existe un cliente con nombre: ' . $nombre);
    }

    /* cerrar el resultset */
    $result->close();
}

//Insertar Pedido
//$sql = 'INSERT INTO `sistema_Clientes`(`nombre`, `direccion`, `telefono`, `email`, `contacto`, `idVendedor`) VALUES ("'.$nombre.'","'.$direccion.'","'.$telefono.'","'.$email.'","'.$contacto.'",'.$idVendedor.')';
$sqlInsertCliente = "INSERT INTO ip_clients (client_name, client_address_1, client_phone, client_email, client_surname, client_date_created, client_date_modified)
                        VALUES ('$nombre','$direccion','$telefono','$email','$contacto',now(),now());";
$sqlInsertClienteMeta = "INSERT INTO ip_client_custom (client_id, client_custom_fieldid, client_custom_fieldvalue)
                        VALUES (LAST_INSERT_ID(),2,$idVendedor);";

echo 'Error SQL1: ' . $sqlInsertCliente . '<br>';
echo 'Error SQL1: ' . $sqlInsertClienteMeta . '<br>';

try {
    echo "In the try<br>";
    // First of all, let's begin a transaction
    $conn->beginTransaction();

    echo "Just Beggined<br>"; // THIS POINT ISN'T REACHED .-

    // A set of queries; if one fails, an exception should be thrown
    $conn->query($sqlInsertCliente);
    $conn->query($sqlInsertClienteMeta);
    //$conn->query('third query');

    // If we arrive here, it means that no exception was thrown
    // i.e. no query has failed, and we can commit the transaction
    $conn->commit();
} catch (Exception $e) {
    // An exception has been thrown
    // We must rollback the transaction
    echo "In exception<br>";
    $conn->rollback();
    echo "Error agregando Cliente: " . $e->getMessage() . "<br>";
}

$conn->close();

?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...