function TryOpenDb() { global $DbLink; global $DbError; global $db_host; global $db_user; global $db_password; global $db_name; /* Connecting, selecting database */ $DbLink = mysql_connect($db_host, $db_user, $db_password); if (!$DbLink) { $DbError = mysql_error(); return FALSE; } if (!mysql_select_db($db_name)) { $DbError = mysql_error(); CloseDb(); return FALSE; } mysql_query("BEGIN"); return $DbLink; }
$dict = array("Product" => $product, "Name" => $name, "Email" => $email, "Licenses" => $count, "Timestamp" => $sn_date, "TransactionID" => $transactionID); $license = licenseDataForDictionary($dict, $key, $privateKey); // Note that the database size for SERIAL_NUMBER was raised from 255 (eSellerate's size) to // a MySQL TEXT field to fit alternate registration schemes. $XmlData["ORDERNOTICEDS"]["ORDERLINES"][$i]["SERIAL_NUMBER"]["_data"] = $license; $to = $email; $from = str_replace(array("##NAME##", "##EMAIL##"), array($name, $email), $from); $subject = str_replace(array("##NAME##", "##EMAIL##"), array($name, $email), $subject); $message = str_replace(array("##NAME##", "##EMAIL##", "##LICENSES##"), array($name, $email, $count), $message); $licenseName = str_replace(array("##NAME##", "##EMAIL##"), array($name, $email), $licenseName); $bcc = str_replace(array("##NAME##", "##EMAIL##"), array($name, $email), $bcc); sendMail($to, $from, $subject, $message, $license, $licenseName, $bcc); } // Build a query string $queryStringValues = array(); foreach ($orderLinesFields as $currentField) { $queryStringValues[] = "\"" . mysql_real_escape_string($XmlData["ORDERNOTICEDS"]["ORDERLINES"][$i][$currentField]["_data"]) . "\""; } $queryString = "INSERT INTO OrderLines (" . join(", ", $orderLinesFields) . ", ORDER_NUMBER, SN_DATE)" . " VALUES (" . join(", ", $queryStringValues) . ", \"{$orderNumber}\", \"{$sn_date}\")"; if ($debug == 1) { echo "{$queryString}\n"; } // Do the insert $sqlResult = mysql_query($queryString); if (!$sqlResult) { ReportFatalError(mysql_error()); } } mysql_query("COMMIT"); CloseDb();
function ReportFatalError($Error) { global $DbLink; Msg($Error); if ($DBLink) { mysql_query("ROLLBACK"); } CloseDb(); exit; }