Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:如何通过从文件加载数据来防止mysql的大容量插入_Php_Mysql_Insert_Sql Injection - Fatal编程技术网

PHP:如何通过从文件加载数据来防止mysql的大容量插入

PHP:如何通过从文件加载数据来防止mysql的大容量插入,php,mysql,insert,sql-injection,Php,Mysql,Insert,Sql Injection,所以我从某个位置提取一个json文件,大约有50000行。我正在使用将数据本地填充'D:/test.txt'加载到表test中进行大容量插入 我将每个元组的所有字段写入一个文本文件,并在其上调用LOAD DATA infle。但是我正在写或插入的数据并没有被转义。在php中,如何转义这种大容量插入?通常我使用预先准备好的语句,但我不知道如何使用LOAD DATA infle。还是有更好的方法进行批量插入 编辑:请求示例文本文件 我只需将此格式的数据写入文本文件: apple,orange,ban

所以我从某个位置提取一个json文件,大约有50000行。我正在使用
将数据本地填充'D:/test.txt'加载到表test
中进行大容量插入

我将每个元组的所有字段写入一个文本文件,并在其上调用
LOAD DATA infle
。但是我正在写或插入的数据并没有被转义。在php中,如何转义这种大容量插入?通常我使用预先准备好的语句,但我不知道如何使用
LOAD DATA infle
。还是有更好的方法进行批量插入

编辑:请求示例文本文件

我只需将此格式的数据写入文本文件:

apple,orange,banana
mango,berry,guava
apricot,nectarine,peaches

apple、orange、banana将是表中的元组。

您可以发布text.txt的示例吗?您是否尝试过mysql\u real\u escape\u strings函数?这不易受到SQL注入的攻击,因为文件中的数据仅解释为数据,而不是代码。