PHPEye开源社区 » Zend Framework 使用讨论 » 在zf中,如何将csv数据导入mysql?
《Programming PHP》第二版上市
2008-7-1 23:20 honking
在zf中,如何将csv数据导入mysql?

在zf中,如何将csv数据导入mysql?

就是使用这样的命令
load data infile 'e:\\book1.csv' into table contents  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' (book_id,title,chapter,section,page_num);
我下列的代码会报错
Mysqli prepare error: This command is not supported in the prepared statement protocol yet

<?php
Zend_Loader::loadClass('Zend_Db_Table');
Zend_Loader::loadClass('Zend_Db_Statement');

class Contents extends Zend_Db_Table
{
        protected $_name = 'contents';
        protected $_primary = 'id';

        public function importFromCsv($path)
        {
                $db = $this->getAdapter();
                $path = $db->quote($path);
                $sql = "load data infile $path into table contents FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' (book_id,title,chapter,section,page_num);";
                $result = $db->query($sql);
        }

}
?>

[[i] 本帖最后由 honking 于 2008-7-1 23:22 编辑 [/i]]

页: [1]


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.