git name
2020-01-22 5454ebd40162281f44297db22ad16d3589553913
commit | author | age
497620 1 <?php
RA 2     $link = mysqli_connect($_ENV["DATABASE_SERVICE_NAME"],$_ENV["DATABASE_USER"],$_ENV["DATABASE_PASSWORD"],$_ENV["DATABASE_NAME"]);
3     if (!$link) {
4         http_response_code (500);
5         error_log ("Error: unable to connect to database\n");
6     die();
7     }
8
9     $query = "SELECT count(*) FROM quote";
10     $result = $link->query($query);
11     if (!$result) {
12         http_response_code (500);
13         error_log ("SQL error: " . mysqli_error($link) . "\n");
14     die();
15     }
16
17     $row = mysqli_fetch_array($result);
18     mysqli_free_result($result);
19
20     $id = rand(1,$row[0]);
21
22     $query = "SELECT msg FROM quote WHERE id = " . $id;
23     $result = $link->query($query);
24     if (!$result) {
25         http_response_code (500);
26         error_log ("SQL error: " . mysqli_error($link) . "\n");
27     die();
28     }
29
30     $row = mysqli_fetch_array($result);
31     mysqli_free_result($result);
32
33     print $row[0] . "\n";
34     
35     mysqli_close($link);
36 ?>