UPDATED - SEE THE ADDITION BELOW
OK, right now, I'm not a developer (maybe someday), I know almost nothing, classes, functions, methods, wrappers, foos, bars, and most of all OOP confuse forever-loving-s from me. That being said, I am sure that there are many things that I could do better and invite your criticism and knowledge. However...
My specific question is: I missed some vital condition for the interaction between the WSDL from which I receive data and PHP + PDO, MySQL combos, and everything will fall apart as soon as I click
The three tables in the code below should normalize a fairly large set of data obtained through the web-based customer service, this part is an automated process (cron job) that extracts code from 6 other files. I had to make some changes to the database to host a new client, and I decided that WTH, give PDO a try again. Only now I donβt feel that the code that I see for him is almost embarrassing, maybe he does it right (yes, I tested it many times many times today, multiple import, everything went without a hitch) I'm going to push the last update is someday tomorrow, and to be honest, I'm a little worried that I missed something serious and will go out with a bunch of corrupted data while I'm out of town this week. Excuse me,if this seems inconsequential, but I spent a lot of time on sites like these, and I know as little as I do, most of the information either suggests too much or is immersed in things that I am not yet competent in (see the list above).
- , , PDO ? , ? , ON DUPLICATE KEY UPDATE ..??
FYI: , . , , . - . 3 , table1 , 2 ..
<pre><code><?php
require_once 'MysqliCurrentLoginQuery.file';
require_once 'MySOAPRequest.file';
$xmlResponse = new SimpleXMLElement($soapresult);
foreach ($xmlResponse->xmlWorkOrders->workOrder as $order) {
try {
require 'MyPDOdbConfigAndConnection.file';
$conn->beginTransaction();
try {
$query1 = "INSERT INTO table(`id`,`b`,`c`,`d`)
VALUES ('" . "','". 1 . "','". 1 . "','". $order->D . "')
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id),d=$order->D";
$result1 = $conn->prepare($query1);
$result1->execute();
$lastid = $conn->lastInsertID();
} catch(PDOExecption $e) {
$conn->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
try {
$query2 = "INSERT INTO table2(`id`, `f`, `g`)
VALUES ('" . "','" . $order->F . "','" . $lastid . "')
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), f=$order->F";
$result2 = $conn->prepare($query2);
$result2->execute();
$lastid = $conn->lastInsertID();
print "<br />" . $conn->lastInsertID() . "<br />";
} catch(PDOExecption $e) {
$conn->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
try {
$dnsdateparts=explode(' ',$order->H);
$query3 = "INSERT INTO table3(`id`, `g`, `h`, `i`)
VALUES ('" . "','" . $order->G . "', STR_TO_DATE('" . $dateparts[0] . "','%m/%d/%Y'),'" . $dateparts[1] . "')
ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), g=G, h=H, i=$lastid";
$result3 = $conn->prepare($query3);
$result3->execute();
$conn->commit();
} catch(PDOExecption $e) {
$conn->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
} catch( PDOExecption $e ) {
print "Error!: " . $e->getMessage() . "</br>";
}
}
?><code><pre>
, . 1 3 , , ! , !
, - , - - , , , ( , , , ).
!!!
! X - ' CRS'Road. , , ! .
- , . , , , , . !
<pre><code>
<?php
require_once ('/path/to/this/file/some.functions.php');
$soapresult = mySoapClientMaker($avariable, $anothervariable);
$xmlResponse = new SimpleXMLElement($soapresult);
foreach ($xmlResponse->xmlWorkOrders->workOrder as $order) {
try {
$conn->beginTransaction();
try {
$query1 = "INSERT INTO table(`id`,`b`,`c`,`d`) "
. "VALUES (:col1, :col2, :col3, :col4)"
. "ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id),d=" . $order->D;
$result1 = $conn->prepare($query1);
$result1 ->bindValue(':col1', NULL, PDO::PARAM_NULL);
$result1 ->bindValue(':col2', 1, PDO::PARAM_INT);
$result1 ->bindValue(':col3', 1, PDO::PARAM_INT);
$result1 ->bindValue(':col4', $order->D, PDO::PARAM_STR);
$result1->execute();
$lastid = $conn->lastInsertID();
} catch(PDOExecption $e) {
$conn->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
try {
$query2 = "INSERT INTO table2(`id`, `f`, `g`) "
. "VALUES (:col1, :col2, :col3) "
. "ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), f=" . $order->F;
$result2 = $conn->prepare($query2);
$result2 ->bindValue(':col1', NULL, PDO::PARAM_NULL);
$result2 ->bindValue(':col2', 1, PDO::PARAM_INT);
$result2 ->bindValue(':col3', $order->D, PDO::PARAM_INT);
$result2->execute();
$lastid = $conn->lastInsertID();
} catch(PDOExecption $e) {
$conn->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
try {
$dateparts=explode(' ',$order->H);
$query3 = "INSERT INTO table3(`id`, `g`, `h`, `i`) "
. "VALUES (:col1, :col2, :col3, :col4) "
. "ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id), g=G, h=H, i=" . $lastid;
VALUES ('" . "','" . $order->G . "', STR_TO_DATE('" . $dateparts[0] . "','%m/%d/%Y'),'" . $dateparts[1] . "')
$result3 = $conn->prepare($query3);
$result3 ->bindValue(':col1', NULL, PDO::PARAM_NULL);
$result3 ->bindValue(':col2', $order->G, PDO::PARAM_INT);
$result3 ->bindValue(':col3', "STR_TO_DATE(" . $dnsdateparts[0] . "','%m/%d/%Y')", PDO::PARAM_STR);
$result3 ->bindValue(':col4', $dateparts[1], PDO::PARAM_STR);
$result3->execute();
$conn->commit();
} catch(PDOExecption $e) {
$conn->rollback();
print "Error!: " . $e->getMessage() . "</br>";
}
} catch( PDOExecption $e ) {
print "Error!: " . $e->getMessage() . "</br>";
}
}
?>
<code><pre>
P.S. , - , .
PDO