简体   繁体   中英

LOAD DATA INFILE not working using \Zend\Db\Adapter

The below code works with directly with PHP's PDO but if I use Zend\\Db\\Adapter it is throwing an error. The first try block does not work while the second one works fine and all data gets imported.

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

The error I get for the first try block:

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)

The location /db/dev/mysqldata/myapps_test is where the mysql server's database files are located.

'?' should be just ? in the first query (the single quotes are added automatically). I think this is what's giving you path problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM