I am passing data from PHP to sql in the form of arrays that look like below:
var_dump($data);
array(
key_id => 'CLA-ARTCC'(length=9)
key2 => 'ZLA'length=3)
key3 => 'LOS ANGELES ACTCC'(length=17)
key4 => 'ACTCC'(length=5)
key5 => 'DEA'(length=3)
key6 => '2555 East Avenue 'P''(length=20)
...
)
I have the started the sql logic like this; which works in some cases but is very error prone, i.e. such as if above array is sent with 'ACTCC
' missing it simply pushes 'DEA
' value to the 'ACTCC
' database column...
example if an array is pushed with no values at key5
(no changes or updates needed to the column); instead it pushes values from incoming key6
as ${data[4]}
...
<?php
.................
$ds = $_POST['data']; // incoming arrays
$fd = json_decode($ds, true);
foreach ($fd as $data) {
array_values($data)
$sql = "MERGE INTO app.table a
using (SELECT '${data[0]}' key_id,
'${data[1]}' key2,
'${data[2]}' key3,
'${data[3]}' key4,
'${data[4]}' key5,
'${data[5]}' key6,
FROM dual) p
ON ( a.key_id= p.key_id )
WHEN matched THEN
UPDATE SET a.key2= p.key2,
a.key3= p.key3,
a.key4= p.key4,
a.key5= p.key5,
INSERT (key_id,
key2,
key3,
key4,
key5,
key6)
VALUES (p.key_id,
p.key2,
p.key3,
p.key4,
p.key5,
p.key6)";
..........
Also, corrupt character fails, i.e. above at key6
- so how could I map my incoming array keys to explicitly match column names in my oracle db table? *
(while keeping my MERGE INTO WHEN MATCHED INSERT structure below?) sry sql noob...