Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

php - Symfony2 Doctrine PDO MySQL Connection with LOAD DATA LOCAL INFILE

Why i have this problem?

Warning: PDO::query(): LOAD DATA LOCAL INFILE forbidden in /srv/www/project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php on line 742

Thats my configuration.

#app/config/config.yml
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        options:
            "PDO::MYSQL_ATTR_LOCAL_INFILE": true

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

I tried the options without leading .

AND if i use this, it works great!

/* @var DoctrineDBALConnection $connection */
$dbhost = $this->getContainer()->getParameter('database_host');
$dbuser = $this->getContainer()->getParameter('database_user');
$dbpass = $this->getContainer()->getParameter('database_password');
$dbname = $this->getContainer()->getParameter('database_name');

$connection = new PDO('mysql:host=' . $dbhost . ';dbname=' . $dbname, $dbuser, $dbpass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => true));

How i can use doctrine from symfony2 instead the own new PDO $connection.

I dont know why doctrine ignore the options... Or cant Doctrine convert the options to the Constant/Integer?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Tried and solved.

#app/config/config.yml
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        options:
            1001: true

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

Doctrine options shouldnt be a constant ^^

Use 1001 instead "PDO::MYSQL_ATTR_LOCAL_INFILE" fixed the problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...