2012-07-11 46 views
1

我想執行以下命令: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

回答

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它的工作原理。

相關問題