-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
39 lines (30 loc) · 941 Bytes
/
Copy pathindex.php
File metadata and controls
39 lines (30 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
function pg_connection_string_from_database_url() {
extract(parse_url($_ENV["DATABASE_URL"]));
return "user=$user password=$pass host=$host dbname=" . substr($path, 1); # <- you may want to add sslmode=require there too
}
$pg_conn = pg_connect(pg_connection_string_from_database_url());
$tableMapping = array(
'adate' => 'thedate',
'adate_time' => 'thedate_time ',
'text' => 'the_text ',
);
$table = 'google_spreadsheet_1';
foreach($_REQUEST['row'] as $id => $data){
$sql = "UPDATE $table SET ";
$colCount = 0;
$updates = array();
$colValues = array();
foreach($data as $column => $value){
$colCount++;
$updates[] = $tableMapping[$column] . "=\${$colCount}";
$colValues[] = $value;
}
$sql .= implode(",", $updates);
$sql .= " WHERE id=\$" . ($colCount + 1);
$colValues[] = $id;
echo "<p>$sql</p>";
echo "<pre>"; var_dump($colValues); echo "</pre>";
pg_query_params($sql, $colValues);
}
echo "UPDATED";