- 很简单只要在初始化的时候加上
array(PDO::MYSQL_ATTR_LOCAL_INFILE => true)
- 如下:
$this->db = new PDO("mysql:host=127.0.0.1;post=3306;dbname=taobao","root","123456",array(PDO::MYSQL_ATTR_LOCAL_INFILE => true));
- 自写代码:
try{
$dsn="mysql:host=127.0.0.1;port=3306;dbname=test";
$user="root";
$pwd="root";
$options=[PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES utf8',PDO::MYSQL_ATTR_LOCAL_INFILE=>true];
$pdo=new PDO($dsn, $user, $pwd, $options);
}catch(PDOException $e){
echo $e->getMessage();
}