Как добавить два значения курсора и ОБНОВИТЬ таблицу

По прошествии половины дня с этим выяснилось, что PDO имеет ошибку, где ...

-

//This would run as expected:
$pdo->exec("valid-stmt1; valid-stmt2;");

-

//This would error out, as expected:
$pdo->exec("non-sense; valid-stmt1;");

-

//Here is the bug:
$pdo->exec("valid-stmt1; non-sense; valid-stmt3;");

Он выполнил бы "valid-stmt1;", остановился на "non-sense;" и никогда не выдавал ошибку. Не будет запускать "valid-stmt3;", возвращать true и лежать в том, что все работает хорошо.

Я ожидал бы, что это ошибка на "non-sense;", но это не так.

Здесь где я нашел эту информацию: Недопустимый запрос PDO не возвращает ошибку

Вот ошибка: https://bugs.php.net/bug.php ? id = 61613


Итак, я попытался сделать это с помощью mysqli и на самом деле не нашел твердого ответа на то, как он работает, поэтому я думал, что просто оставлю его здесь для тех, кто хотите использовать ..

try{
    // db connection
    $mysqli = new mysqli("host", "user" , "password", "database");
    if($mysqli->connect_errno){
        throw new Exception("Connection Failed: [".$mysqli->connect_errno. "] : ".$mysqli->connect_error );
        exit();
    }

    // read file.
    // This file has multiple sql statements.
    $file_sql = file_get_contents("filename.sql");

    if($file_sql == "null" || empty($file_sql) || strlen($file_sql) <= 0){
        throw new Exception("File is empty. I wont run it..");
    }

    //run the sql file contents through the mysqli's multi_query function.
    // here is where it gets complicated...
    // if the first query has errors, here is where you get it.
    $sqlFileResult = $mysqli->multi_query($file_sql);
    // this returns false only if there are errros on first sql statement, it doesn't care about the rest of the sql statements.

    $sqlCount = 1;
    if( $sqlFileResult == false ){
        throw new Exception("File: '".$fullpath."' , Query#[".$sqlCount."], [".$mysqli->errno."]: '".$mysqli->error."' }");
    }

    // so handle the errors on the subsequent statements like this.
    // while I have more results. This will start from the second sql statement. The first statement errors are thrown above on the $mysqli->multi_query("SQL"); line
    while($mysqli->more_results()){
        $sqlCount++;
        // load the next result set into mysqli's active buffer. if this fails the $mysqli->error, $mysqli->errno will have appropriate error info.
        if($mysqli->next_result() == false){
            throw new Exception("File: '".$fullpath."' , Query#[".$sqlCount."], Error No: [".$mysqli->errno."]: '".$mysqli->error."' }");
        }
    }
}
catch(Exception $e){
    echo $e->getMessage(). " 
".$e->getTraceAsString()."
"; }

-8
задан bot 21 October 2015 в 03:50
поделиться