From 3e584d4044258c1e10b5cbf53bd4f92b350e50e3 Mon Sep 17 00:00:00 2001 From: m-takatsuki <26-m-takatsuki-webstar@it-college.co.jp> Date: Wed, 28 Oct 2026 16:54:17 +0900 Subject: [PATCH] Ex.02 --- Ex02.php | 1 + Ex02_query.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Ex02_query.php diff --git a/Ex02.php b/Ex02.php index 25687a7..3c0a4ff 100644 --- a/Ex02.php +++ b/Ex02.php @@ -22,6 +22,7 @@ require_once __DIR__ . '/Ex02_query.php'; $employees = getEmployees(); + ?> diff --git a/Ex02_query.php b/Ex02_query.php new file mode 100644 index 0000000..0c4bb2a --- /dev/null +++ b/Ex02_query.php @@ -0,0 +1,37 @@ +prepare('INSERT INTO employees + (id,name,dep_id,project_id,salary) + VALUES (:id, :name, :dep_id, :project_id, :salary)'); + + $stt->bindValue(':id',$_POST['id']); + $stt->bindValue(':name',$_POST['name']); + $stt->bindValue(':dep_id',$_POST['dep_id']); + $stt->bindValue(':project_id',$_POST['project_id']); + $stt->bindValue(':salary',$_POST['salary']); + +// "employees" テーブルから全レコードを取得する SELECT クエリを実行する。 + $sql = "SELECT * FROM employees"; + +// - fetchAll() を用いて、結果セットを PDO::FETCH_ASSOC 形式で取得し、その結果を return する。 +$results = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // SQLを実行 +$stmt->execute(); + + return $results; +} \ No newline at end of file