Show sourcecode
The following files exists in this folder. Click to view.
admin.php
fetch_car_things.php
fetch_kompisar.php
fetch_users.php
mysql1.php
mysql2.php
mysql3.php
mysql3_satt_att_sortera.php
mysql3car.php
mysql3garage.php
mysql3owner.php
welcome.php
fetch_users.php
28 lines UTF-8 Windows (CRLF)
<?php
/**
* Fetches all data from users table
*/
// Signalera att vi kommer retunera JSON
header('Content-Type: application/json');
include('../../incl/dbconnection.php');
try {
// Kör SQL kod
$sql = "SELECT * FROM users";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
// Hämta datan från users, spara i associative array format
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Gör om array till json kod
echo json_encode($results);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => 'Database query failed: ' . $e->getMessage()]);
}
$dbconn = null
?>