Magento - 如何将文件加载到数据库中

时间:2012-07-11 13:31:47

标签: mysql magento

我想执行以下命令:

INTO TABLE example_table FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' (field1,field2,field3);

我试着这样做:

$app = Mage::app();

umask(0);

Mage::setIsDeveloperMode(true);

$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$write->query("INTO TABLE example_table
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n'
(field1,field2,field3)");

我还要CREATE OR REPLACE VIEW...TRUNCATE example_table

我得到的错误是:

Error: Warning: PDOStatement::execute(): LOAD DATA LOCAL INFILE forbidden in \lib\Zend\Db\Statement\Pdo.php on line 228

1 个答案:

答案 0 :(得分:3)

好的,问题解决了。

$dbConfig = array(
    'host'      => 'HOST',
    'username'  => 'USER',
    'password'  => 'PASS',
    'dbname'    => 'DBNAME',
    'driver_options'=> array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8')
);
$db_magento = Zend_Db::factory('Pdo_Mysql', $dbConfig);
$db_magento->query("TRUNCATE table1");
    $db_magento->query("LOAD DATA INFILE '{$file_name}'
    INTO TABLE table1
    FIELDS TERMINATED BY ';'
    LINES TERMINATED BY '\n'
    (field1,field2,field3)");

我无法使用LOAD DATA LOCAL INFILE,但没有使用LOCAL