LOAD DATA INFILE使用\ Zend \ Db \ Adapter无法正常工作

时间:2013-04-16 17:31:17

标签: php mysql zend-framework pdo

以下代码直接与PHP的PDO一起使用但如果我使用Zend \ Db \ Adapter则会抛出错误。第一个尝试块不起作用,而第二个尝试块工作正常,所有数据都被导入。

try {
    $dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
    $result = $dbAdapter->query("LOAD DATA INFILE '?' INTO TABLE users FIELDS TERMINATED BY ',' ENCLOSED BY '" . '"' . "' LINES TERMINATED BY '\n' IGNORE 1 LINES",
                    array('/tmp/feed.csv'));
} catch (PDOException $e) {
    print "Error1!: " . $e->getMessage() . "<br/>";
}
try {
    $dbh = new PDO('mysql:host=localhost;dbname=myapps_test', 'myapps_test_user', 'pwd');
    $result = $dbh->exec("LOAD DATA INFILE '/tmp/feed.csv' INTO TABLE users FIELDS TERMINATED BY ',' ENCLOSED BY '" . '"' . "' LINES TERMINATED BY '\n' IGNORE 1 LINES");
    $dbh = null;
} catch (PDOException $e) {
    print "Error2!: " . $e->getMessage() . "<br/>";
}

第一次尝试阻止我得到的错误:

Zend\Db\Adapter\Exception\InvalidQueryException: Statement could not be executed

Caused by
PDOException: SQLSTATE[HY000]: General error: 13 Can't get stat of '/db/dev/mysqldata/myapps_test/?' (Errcode: 2)

位置/ db / dev / mysqldata / myapps_test是mysql服务器的数据库文件所在的位置。

1 个答案:

答案 0 :(得分:0)

在第一个查询中,

'?'应该只是?(单引号会自动添加)。我认为这是给你路径问题的原因。