· 6 years ago · Nov 26, 2019, 07:18 PM
1 if($_SERVER['REQUEST_METHOD']=="GET"){
2 $testStudent = array(
3 "name" => 'test',
4 'math' => 0,
5 'phis' => 0,
6 'prog' => 0,
7 'phisical' => 0,
8 'progress' => 0,
9 );
10 $testStudentObj = (object)$testStudent;
11
12 $createTableSql = "CREATE TABLE IF NOT EXISTS studentsv1 (`student_name` varchar(255),`math` int(3) DEFAULT '0',`phis` int(3) DEFAULT '0',`prog` int(3) DEFAULT '0',`phisical` int(3) DEFAULT '0',`progress` int(3) DEFAULT '0')";
13 $insertTestData = "INSERT INTO studentsv1 (`student_name`, `math`,`phis`,`prog`,`phisical`,`progress`) VALUES ('name',0,0,0,0,0) WHERE NOT EXISTS(SELECT student_name FROM studentsv1 WHERE `student_name` = 'name';) ";
14
15 $stmt1=$pdo->prepare($createTableSql);
16 $stmt1->execute();
17
18 $pdo->query($insertTestData);
19 $selectAllSql = "SELECT * FROM `studentsv1` ";
20 $stmt2 =$pdo->prepare($selectAllSql);
21 $stmt2->execute();
22
23 $rows = $stmt2->fetchAll(PDO::FETCH_ASSOC);
24 echo json_encode($rows);
25 http_response_code(200);
26 }