Menu principale:
CREATE TABLE user ( id INT UNSIGNED NOT NULL AUTO_INCREMENT , firstName VARCHAR(100) NOT NULL , lastName VARCHAR(100) NOT NULL , email VARCHAR(100) NOT NULL , PRIMARY KEY ('id') ) ENGINE = InnoDB; INSERT INTO user (id, firstName, lastName, email) VALUES (NULL, 'Simone', 'D\'Amico', 'simone@email.it'), (NULL, 'Mario', 'Rossi', 'mario@email.it');
$user = 'root'; $password = 'root'; $db = 'test'; $host = 'localhost'; $port = 8889; $conn = new PDO("mysql:host=$host; dbname=$db; port=$port", $user, $password);
$result = []; $stmt = $conn->query("SELECT * FROM user"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ $result[] = $row; } echo json_encode($result);
[ { id: "1", firstName: "Simone", lastName: "D'Amico", email: "simone@email.it" }, { id: "2", firstName: "Mario", lastName: "Rossi", email: "mario@email.it" }