Home >Backend Development >PHP Tutorial >Detailed operations of MySQL batch importing data through LOAD DATA INFILE under the TP5 framework
LOAD DATA INFILE Statement Usage Reference Manual The statement parameters in this article use default values
PHP: TP Framework Environment
// 定义文件路径 $file_path = 'LOAD_DATA_LOCAL_INFILE.txt'; set_time_limit(1000); $fhandler = fopen($file_path,'w'); if($fhandler == false){ // 文件打开失败 } $id = 7; $add_time = time(); // 向文件中写入数据 这里是写入 10万条 $sql = "$id\t$add_time"; $num = 100000; $i = 0; while($i < $num){ $i++; fwrite($fhandler,$sql."\r\n"); } $dbc = [ // 这里是数据库信息 // 数据库连接参数 可能需要这些参数 这里是在 TP 框架中需要设置的参数 'params' => [PDO::ATTR_CASE => PDO::CASE_LOWER,PDO::ATTR_EMULATE_PREPARES => true,PDO::MYSQL_ATTR_LOCAL_INFILE => true], ]; // thinkphp 执行SQL 语句方式 $rs = Db::connect($dbc)->execute("LOAD DATA LOCAL INFILE '{$file_path}' INTO TABLE youtablename (cid,add_time)");
The above is about the operatic operation of MySQL batch importing data through LOAD DATA INFILE. For more related content, please visit the PHP Chinese website: MySQL Video Tutorial
The above is the detailed content of Detailed operations of MySQL batch importing data through LOAD DATA INFILE under the TP5 framework. For more information, please follow other related articles on the PHP Chinese website!