Problema almacenando 200.000 registros
Publicado por Jorge (3 intervenciones) el 27/01/2023 19:10:58
Hola! llevo varios días batallando con algo que no entiendo por que sucede.
Estoy almacenando casi 200.000 registros con este script:
Lo raro es que me esta almacenando 193233 registros en la tabla productos, 203784 en la tabla product_date, y 186160 en la tabla product_extra pero lo lógico debería ser la misma cantidad de registros en las tres tablas.
Los campos son null en todas las tablas menos el campo id que es primary. El script tarda unos 10min en cargar y no aparece ningún error en los logs y cuando termina me imprime en pantalla el ok.
Estoy almacenando casi 200.000 registros con este script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
ini_set('memory_limit', '8192M');
ini_set('realpath_cache_size', -1);
session_start();
include("../../../includes/conn.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'OCULTO');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Accept: */*';
$headers[] = 'Authorization: Bearer OCULTO';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$key= json_decode($result,TRUE);
for($i=0;$i<count($key);$i++){
$stmt1 = $pdo->prepare("SELECT id FROM products WHERE id=".$key[$i]["id"]." ");
$stmt1->execute();
if($stmt1 -> rowCount() > 0) { } else {
if(isset($key[$i]["id"]) && !empty($key[$i]["id"])) {
echo "....".$i."....<br/>";
$pdo->prepare("INSERT INTO products (`id`,`manufacturer`,`sku`,`ean13`,`wholesalePrice`,`retailPrice`,`dateAdd`,`active`,`taxRate`,`taxId`,`inShopsPrice`,`condition`,`logisticClass`) VALUES ('".$key[$i]["id"]."','".$key[$i]["manufacturer"]."','".$key[$i]["sku"]."','".$key[$i]["ean13"]."','".$key[$i]["wholesalePrice"]."','".$key[$i]["retailPrice"]."','".$key[$i]["dateAdd"]."','".$key[$i]["active"]."','".$key[$i]["taxRate"]."','".$key[$i]["taxId"]."','".$key[$i]["inShopsPrice"]."','".$key[$i]["condition"]."','".$key[$i]["logisticClass"]."')")->execute();
$pdo->prepare("INSERT INTO product_date (`id`,`dateUpd`,`dateUpdDescription`,`dateUpdImages`,`dateUpdStock`) VALUES ('".$key[$i]["id"]."','".$key[$i]["dateUpd"]."','".$key[$i]["dateUpdDescription"]."','".$key[$i]["dateUpdImages"]."','".$key[$i]["dateUpdStock"]."')")->execute();
$pdo->prepare("INSERT INTO product_extra (`id`,`weight`,`height`,`width`,`depth`,`sku`) VALUES ('".$key[$i]["id"]."','".$key[$i]["weight"]."','".$key[$i]["height"]."','".$key[$i]["width"]."','".$key[$i]["depth"]."','".$key[$i]["sku"]."')")->execute();
if(isset($key[$i]["priceLargeQuantities"])) {
for($a=0;$a<count($key[$i]["priceLargeQuantities"]);$a++){
$pdo->prepare("INSERT INTO product_pricelargequantities (id,`quantity`,price) VALUES ('".$key[$i]["priceLargeQuantities"][$a]["id"]."','".$key[$i]["priceLargeQuantities"][$a]["quantity"]."','".$key[$i]["priceLargeQuantities"][$a]["price"]."')")->execute();
}
}
} } } echo "ok";
Lo raro es que me esta almacenando 193233 registros en la tabla productos, 203784 en la tabla product_date, y 186160 en la tabla product_extra pero lo lógico debería ser la misma cantidad de registros en las tres tablas.
Los campos son null en todas las tablas menos el campo id que es primary. El script tarda unos 10min en cargar y no aparece ningún error en los logs y cuando termina me imprime en pantalla el ok.
Valora esta pregunta


0