1

I'm using PHP with PDO connection. I'm having problem que a DATA LOAD query. All others query's are OK. This is my code:

function query($sql, $BANCO = _BASE)
{       
    try
    {
        $PDO = new PDO( 'mysql:host=' . _HOST . ';dbname=' . $BANCO, _USER, _PASS, 
            array(
                PDO::MYSQL_ATTR_LOCAL_INFILE => true 
                ,PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
                ,PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
                ,PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
                ,PDO::ATTR_EMULATE_PREPARES => false
            )
        );
    }
    catch ( PDOException $e )
    {
        p('Erro ao conectar com o MySQL.<br />QUERY: ' . $sql . '<br />ERRO: ' . $e->getMessage());
    }

    $RESULTADO = $PDO->prepare($sql);
    $RESULTADO->execute();
    $DADOS = $RESULTADO->fetchAll();
    $RESULTADO->nextRowset();

    return $DADOS;
}

When i run this query, it give's me an error.

QUERY:

        LOAD DATA LOCAL INFILE '/var/www/html/config/dados/2016/10/23/rvca_001.csv'
        IGNORE INTO TABLE zanox_data_load
        CHARACTER SET UTF8 FIELDS TERMINATED BY '   ' ENCLOSED BY '"' LINES TERMINATED BY '/r' IGNORE 1 LINES 
        SET 
            data_atualizacao = NOW(),  
            identificador = SLUG(nome)

ERROR:

Fatal error:  Uncaught PDOException: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in /var/www/html/config/config.php:44

I've already try to read some posts, but nothing worked. Can anyone help me?

tibasce
  • 133
  • 12
  • I'm not sure, but I would try terminating each individual query with a semi-colon. That may be why it is claiming about 'unbuffered queries'. – Carafini Oct 24 '16 at 02:26
  • How would i do this? – tibasce Oct 24 '16 at 02:31
  • I found this answer which might be what you're looking for : http://stackoverflow.com/questions/17434102/causes-of-mysql-error-2014-cannot-execute-queries-while-other-unbuffered-queries – Carafini Oct 24 '16 at 02:53
  • I've already tried to use closeCursor(), but still got the error. – tibasce Oct 24 '16 at 03:08

0 Answers0