-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
31 lines (28 loc) · 858 Bytes
/
server.php
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
<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
function getConnection() {
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname="beisbol";
$dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh -> exec("set names utf8");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh;
}
// TOMAMOS NUESTRO JSON RECIBIDO DESDE LA PETICION DE ANGULAR JS Y LO LEEMOS
$time = date('r');
$d=" The server time is: {$time}\n\n";
$sql ="SELECT nombre FROM equipos";
try {
$db = getConnection();
$stmt = $db->query($sql);
$detalle = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
echo "data: " .json_encode($detalle).$d ;
} catch(PDOException $e) {
echo '{"error":{"text":}}';
}
flush();
?>