CMXX - cartest - migrationscript
This commit is contained in:
74
dev.php
74
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user