PHP / SQL / XMLReader - Update big table using another
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:
- 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.
- 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++;
}
php mysql zend-framework xmlreader
add a comment |
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:
- 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.
- 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++;
}
php mysql zend-framework xmlreader
Try to change your approach - load data from both XMLs to temporary SQL tables and then do update directly in DBMS by suitable SQL queries, not in PHP. Updating data inproducts
andproducts_prices
will be easier to manage and faster than doing it row by row in PHP script.
– Daniel Gadawski
Nov 25 '18 at 22:30
add a comment |
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:
- 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.
- 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++;
}
php mysql zend-framework 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:
- 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.
- 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++;
}
php mysql zend-framework xmlreader
php mysql zend-framework xmlreader
asked Nov 23 '18 at 2:53
KurczakovskyKurczakovsky
357
357
Try to change your approach - load data from both XMLs to temporary SQL tables and then do update directly in DBMS by suitable SQL queries, not in PHP. Updating data inproducts
andproducts_prices
will be easier to manage and faster than doing it row by row in PHP script.
– Daniel Gadawski
Nov 25 '18 at 22:30
add a comment |
Try to change your approach - load data from both XMLs to temporary SQL tables and then do update directly in DBMS by suitable SQL queries, not in PHP. Updating data inproducts
andproducts_prices
will be easier to manage and faster than doing it row by row in PHP script.
– Daniel Gadawski
Nov 25 '18 at 22:30
Try to change your approach - load data from both XMLs to temporary SQL tables and then do update directly in DBMS by suitable SQL queries, not in PHP. Updating data in
products
and products_prices
will be easier to manage and faster than doing it row by row in PHP script.– Daniel Gadawski
Nov 25 '18 at 22:30
Try to change your approach - load data from both XMLs to temporary SQL tables and then do update directly in DBMS by suitable SQL queries, not in PHP. Updating data in
products
and products_prices
will be easier to manage and faster than doing it row by row in PHP script.– Daniel Gadawski
Nov 25 '18 at 22:30
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440124%2fphp-sql-xmlreader-update-big-table-using-another%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440124%2fphp-sql-xmlreader-update-big-table-using-another%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try to change your approach - load data from both XMLs to temporary SQL tables and then do update directly in DBMS by suitable SQL queries, not in PHP. Updating data in
products
andproducts_prices
will be easier to manage and faster than doing it row by row in PHP script.– Daniel Gadawski
Nov 25 '18 at 22:30