From d44240b7ad84f67ae8240b3c79fe0d4fd26afd11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Fri, 15 Nov 2024 08:48:36 +0100 Subject: [PATCH] CMXX - cartest - migrationscript --- dev.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/dev.php b/dev.php index 0955e94..0d27912 100644 --- a/dev.php +++ b/dev.php @@ -7,19 +7,75 @@ include './assets/functions.php'; include './settings/settings.php'; include './settings/config.php'; -//Connect to DB -$pdo = dbConnect($dbname); -$plug_sn ='22050695'; -//GET -$sql ='SELECT accounthierarchy FROM equipment WHERE serialnumber = ?'; +//----------------------------------------- +//Connect to DATABASE FROM WHERE TO MIGRATE +//----------------------------------------- + +$dbcon_dev = 'VELITIProduct'; +$pdo = new PDO('mysql:host=' . $db . ';dbname=' . $dbcon_dev . ';charset=utf8', $dbuser, $dbpw); +$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +//----------------------------------------- +//----------------------------------------- + +//GET DATA +$sql ="SELECT carbrand,cartype,header,questions,datapoints,created,createdby FROM cartest where createdby like '%r2r%'"; $stmt = $pdo->prepare($sql); //Excute Query -$stmt->execute([$plug_sn]); +$stmt->execute(); //Get results $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); -var_dump($messages[0]['accounthierarchy']); +$accounthierarchy = '{"salesid":"21-Total Safety Solutions B.V.","soldto":"48-TSS-Demo","shipto":"2854-R2R","location":"","section":"Demo TSS"}'; + +foreach ($messages as &$message ){ + //ADD ACCOUNTHIERARCHY + $message['accounthierarchy'] = $accounthierarchy; + + //default whereclause + $whereclause = ''; + + //CREATE EMPTY STRINGS + $clause = ''; + $clause_insert =''; + $input_insert = ''; + + $post_content = $message; + + //CREAT NEW ARRAY AND MAP TO CLAUSE + if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'delete' || $key == 'rowID'){ + //do nothing + } + else { + $criterias[$key] = $var; + $clause .= ' , '.$key.' = ?'; + $clause_insert .= ' , '.$key.''; + $input_insert .= ', ?'; // ? for each insert item + $execute_input[]= $var; // Build array for input + } + } + } + + //CLEAN UP INPUT + $clause = substr($clause, 2); //Clean clause - remove first comma + $clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma + $input_insert = substr($input_insert, 1); //Clean clause - remove first comma + + //----------------------------------------- + //Connect to TARGET DATABASE + //----------------------------------------- + + $pdo2 = dbConnect($dbname); + + //----------------------------------------- + //----------------------------------------- + //SQL EXECUTION + $sql = 'INSERT INTO cartest ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo2->prepare($sql); + //$stmt->execute($execute_input); + +} - -?> \ No newline at end of file