-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
38 lines (33 loc) · 1.08 KB
/
Copy pathindex.php
File metadata and controls
38 lines (33 loc) · 1.08 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
<?php
$myserver = "rg-masson-postgre.postgres.database.azure.com";
$myusername = $_ENV['myusername'];
$mypassword = $_ENV['password'];
$mydb = "mybase";
$connection = pg_connect("host=$myserver dbname=$mydb user=$myusername password=$mypassword");
$request_method = $_SERVER["REQUEST_METHOD"];
function getUserTel()
{
global $connection;
$result = pg_query($connection, "SELECT * FROM users");
if (!$result) {
echo json_encode(array("error" => "Une erreur est survenue."));
exit;
}
$response = array();
while ($row = pg_fetch_row($result)) {
$response[] = array("Id" => $row[0], "username" => $row[1], "tel" => $row[2]);
}
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header('Content-Type: application/json');
echo json_encode($response, JSON_PRETTY_PRINT);
}
switch($request_method)
{
case 'GET':
getUserTel();
break;
default:
header("HTTP/1.0 405 Method Not Allowed");
break;
}