PHP / SQL / XMLReader - 使用另一个更新大表

Im using XMLReader to import product to my SQL table. There is 62419 items in 'products' table. Sometime in first .xml file there is no price for products but they are on second file. So im using again XMLReader to store this prices in 'products_prices' table. Right now i`v got 50912 item in this table. I need solution how update prices in 'products' table using 'products_prices'.

Schema for 'products' table:

id
pxmlId
pprice
psale_price

Schema for 'products_prices' table:

id
pxml_id
pprice
psale_price

'pxmlId' and 'pxml_id' are the same - and this is ID product from both .xml files.

What I've tried:

  1. First fill 'products_prices' table then when XMLReader read .xml files for 'products' table i send query to 'products_prices' if there is any 'pxml_id'. if is then get prices and update last query.

This take to long and sometime i`v get '500 error'.

What I think I can do: 1. Get items from 'products_prices' and put them to big array then when XMLReader read .xml files for 'products' search in this array for prices.

  1. Merge this .xml files using XMLReader, but i dont if this is possible.

This is code for XMLReader:

    $reader = new XMLReader();
    $reader->open($wpis->feed);

    while($reader->read() && $reader->name != 'item' && $reader->name != 'entry'){;}

    $i = 0;
    $e = 0;
    while($reader->name === 'item')
    {
        $parent = $reader->expand();
        $price = $parent->getElementsByTagName('price')->item(0)->nodeValue;
        $description = $parent->getElementsByTagName('description')->item(0)->nodeValue;
        $title = $parent->getElementsByTagName('title')->item(0)->nodeValue;
        $sale_price = $parent->getElementsByTagName('sale_price')->item(0)->nodeValue;
        $gtin = $parent->getElementsByTagName('gtin')->item(0)->nodeValue;
        $availability = $parent->getElementsByTagName('availability')->item(0)->nodeValue;
        $link = $parent->getElementsByTagName('link')->item(0)->nodeValue;
        $condition = $parent->getElementsByTagName('condition')->item(0)->nodeValue;
        $image_link = $parent->getElementsByTagName('image_link')->item(0)->nodeValue;
        $brand = $parent->getElementsByTagName('brand')->item(0)->nodeValue;
        $pxmlId = $parent->getElementsByTagName('id')->item(0)->nodeValue;

        $clean_price = preg_replace('/[^.0-9]/', '', $price);
        $sale_clean_price = preg_replace('/[^.0-9]/', '', $sale_price);

        if($gtin){
            $gtins = $gtin;
        } else {
            $gtins = 'nogtin';
        }

        $data = array(
            'ptitle' => trim($title),
            'pdesc' => $description,
            'pprice' => $clean_price,
            'psale_price' => $sale_clean_price,
            'pgtin' => $gtins,
            'pavailability' => $availability,
            'plink' => $link,
            'pcondition' => $condition,
            'pimage' => $image_link,
            'pbrand' => $brand,
            'pbrand_tag' => zmiana($brand),
            'pshop_currency' => $wpis->waluta,
            'pshop' => $wpis->nazwa,
            'pshop_id' => $wpis->id,
            'pxmlId' => $pxmlId
        );

        $db->insert('gmc_products', $data);
        $lastId = $db->lastInsertId();

        $reader->next('item');

        $i++;
    }