Massive SQL request
-
There's a combination of INSERT INTO, which should be inserted into 2,000 records. The problem is, if I want to do this request from the php, the request will not be implemented. If it's handwritten, it's all on edge. Where to dig, tell me? And does php have any methods to interact with such big requests?
Example
$str = "INSERT INTO keywords (id,article_id,word,count)VALUES(NULL,'16','Google','122');INSERT INTO keywords (id,article_id,word,count)VALUES(NULL,'16','Планета','51');INSERT INTO keywords (id,article_id,word,count)VALUES(NULL,'16','Земля','51');........." ..
$query = $connect->query($str);
var_dump($query) // false
-
Actually, you can't repeat the request.
INSERT INTO
and the resulting line may look like:$str = "INSERT INTO keywords (id,article_id,word,count) VALUES (NULL,'16','Google','122'), (NULL,'17','Google','123'), (NULL,'18','Google','124'), (NULL,'19','Google','125')";
As a result, the line can be shaped:
$str = "INSERT INTO keywords (id,article_id,word,count) VALUES "; for (int i=0; i<2000; i++) { // откуда данные берёте, я не в курсе, поэтому примерно так $str += "(NULL,'$row1[i]','$row2[i]','$row3[i]'),"; } $str = substr($str,0,-1);//чтобы убрать последнюю запятую
$query = $connect->query($str);
By the way, if id is an auto-increment counter, it doesn't have to be transferred.
NULL
♪INSERT INTO keywords (article_id,word,count) VALUES ('16','Google','122')