-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_location.php
More file actions
59 lines (45 loc) · 1.57 KB
/
Copy pathupdate_location.php
File metadata and controls
59 lines (45 loc) · 1.57 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
// PostgreSQL connection parameters
$host = 'dpg-d4h6rvumcj7s73brb53g-a.oregon-postgres.render.com';
$port = '5432';
$dbname = 'dbname_odlo';
$user = 'dbuser';
$password = 'IRPMRemSEj0V0Kj3lv2XmFEuN5gIY3dR';
// Connect to PostgreSQL
$conn_string = "host=$host port=$port dbname=$dbname user=$user password=$password";
$conn = pg_connect($conn_string);
if (!$conn) {
die("Connection failed: " . pg_last_error());
}
// Track ID and new location
$track_id = 'JJHDJ1HG89';
$new_location = 'Frankfurt 🇩🇪';
// Check if track exists
$query = "SELECT id, location FROM track WHERE pid = $1";
$result = pg_query_params($conn, $query, array($track_id));
if (!$result) {
die("Query failed: " . pg_last_error($conn));
}
if (pg_num_rows($result) == 0) {
echo "Track ID $track_id not found in database.\n";
pg_close($conn);
exit;
}
$row = pg_fetch_assoc($result);
$current_location = $row['location'];
$id = $row['id'];
echo "Current location for Track ID $track_id: $current_location\n";
// Update the location
$update_query = "UPDATE track SET location = $1 WHERE id = $2";
$update_result = pg_query_params($conn, $update_query, array($new_location, $id));
if (!$update_result) {
die("Update failed: " . pg_last_error($conn));
}
echo "Location updated successfully to: $new_location\n";
// Verify the update
$verify_query = "SELECT location FROM track WHERE id = $1";
$verify_result = pg_query_params($conn, $verify_query, array($id));
$verify_row = pg_fetch_assoc($verify_result);
echo "Verified new location: " . $verify_row['location'] . "\n";
pg_close($conn);
?>