PHP + PDO错误 - 一般错误:2014

时间:2016-10-24 02:14:31

标签: php mysql pdo

我使用PHP与PDO连接。我遇到问题是对数据加载进行查询。所有其他查询都没问题。这是我的代码:

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;
}

当我运行此查询时,它会给我一个错误。

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

我已经尝试阅读一些帖子,但没有任何效果。任何人都可以帮助我吗?

0 个答案:

没有答案