MSSQL: SQLSTATE[] (null) (Severity 0) after loading 1000 lines

Asked

Viewed 176 times

0

I have some reports where I need to perform new SQL queries in the loop. These reports are running in PHP and datatables.

In some moments, when the number of lines reaches a volume greater than 1000, the error MSSQL: SQLSTATE[] (null) (Severity 0) is displayed, aborting code execution.

Connection function:

 function pdo_mysql($sql){

    f_log($sql);

    $host = ***;
    $user = ***;
    $pass = ***;
    $db   = ***;

    try {
        $PDO = new PDO( 'mysql:host=' . $host . ';dbname=' . $db, $user, $pass );
    }
    catch ( PDOException $e ) {
        echo 'Erro ao conectar com o MySQL: ' . $e->getMessage(); exit;
    }

    $result = $PDO->query( $sql );

    if (is_array($result)){
        $row = $result->fetchAll( PDO::FETCH_ASSOC );
    }else{
        $row = $result;
    }

    return $row;

 }

File template presenting problem:

$sql = "SELECT ....";
$return = pdo_mssql($sql);

foreach ($return as $row){

    $sql2 = "SELECT ...."
    $return = pdomssql($sql2);

    foreach ($return2 as $row2){
        // Guarda dados em variáveis.
    }

    $sql2 = "SELECT ...."
    $return = pdomssql($sql2);

    foreach ($return2 as $row2){
        // Guarda dados em variáveis.
    }

    $sql2 = "SELECT ...."
    $return = pdomssql($sql2);

    foreach ($return2 as $row2){
        // Guarda dados em variáveis.
    }

    // Exibe resultados

}

Has anyone gone through anything like it or has any suggestions?

Thank you

  • Enter the code.

  • Just for test, make your consultation with top, SELECT TOP 300 * FROM ... see if the error happens. Need to bring all records?

  • It’s just example or you actually have 3 foreach within one another running the same query?

  • When the query returns fewer rows or has a TOP 900 for example, the error is not displayed. Already related to foreach, I have 10 of them inside this loop... Unfortunately I need to keep them.

  • With each turn of the external foreach these 10 queries are re/executed, it’s a lot, I think you need to rethink this.

  • But we have no restriction on the execution time. The problem is the code interruption... Even though it is a lot, the loop should not continue running until the end?

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.