prepare("select id, coord, color from pixel where id > :newerthan order by id"); $stmt->bindParam(":newerthan", $_GET["newerthan"]); $result = $stmt->execute(); if (!$result) pdo_die($stmt); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); echo json_encode($rows); } elseif ($coord = @isset($_GET["coord"])) { add($coord, $_GET["color"]); } if (isset($_GET["hit"])) { gen_hits(); } function gen_hits() { for ($i = 1; $i <= 1; $i++) { $row = rand(0, 49); $col = rand(0, 49); add("$row-$col", "red"); } } function add($coord, $color) { $conn = getconn(); $stmt = $conn->prepare("insert into pixel(coord, color) values(:coord, :color)"); $stmt->bindParam(":coord", $coord); $stmt->bindParam(":color", $color); $result = $stmt->execute(); if (!$result) pdo_die($stmt); }