1

下面的代码直接与 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/>";
}

我在第一个 try 块中得到的错误:

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 服务器的数据库文件所在的位置。

4

1 回答 1

0

'?'应该只是?在第一个查询中(单引号会自动添加)。我认为这就是给您带来路径问题的原因。

于 2013-04-16T18:13:38.207 回答