I have been looking for a solution that allows load data queries with zend framework like:
LOAD XML LOCAL INFILE '$dbFile' INTO TABLE mytable ROWS IDENTIFIED BY '<object>';
When I try to execute this query, i get the following error:
Warning: PDO::exec() [pdo.exec]: LOAD DATA LOCAL INFILE forbidden
However if I output the query and copy/paste it into an editor like HeidiSQL the query works. I searched for an answer and found that I should set the driver option PDO::MYSQL_ATTR_LOCAL_INFILE but it does not seem to work.
I would like to use application.ini to set the driver option:
resources.multidb.mydb.adapter = "Pdo_Mysql"
resources.multidb.mydb.dbname = "mydb"
resources.multidb.mydb.username = "myuser"
resources.multidb.mydb.password = "mypass"
resources.multidb.mydb.driver_options.PDO::MYSQL_ATTR_LOCAL_INFILE = true
resources.multidb.mydb.driver_options.1001 = true
I tried it the following way too but got the same error:
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'testing');
$dbParams = $config->resources->multidb->mydb->toArray();
$dbParams['driver_options'] = array(PDO::MYSQL_ATTR_LOCAL_INFILE => '1');
$db = Zend_Db::factory($config->resources->multidb->mydb->adapter, $dbParams);
Am I overlooking something? Or maybe setting the options wrong? I also read that mysql must be compiled with --enable-load-data or something but the query works with an sql editor so it should work through php.
I found an interesting implementation of local infiles in the Rend (Rapid Zend) Framework.
Basically, the file has a class for the PDO object and has a method like this:
/**
* Set the local infile flag
*
* @param boolean $allowLocalInfile
* @return Rend_Factory_Database_Pdo_Mysql
*/
public function setAllowLocalInfile($allowLocalInfile)
{
$this->_options["driver_options"][PDO::MYSQL_ATTR_LOCAL_INFILE] = $allowLocalInfile;
return $this;
}
I'm sure some more browsing in that open source repository would reveal some tricks to solve your problem.
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.