回答です

This commit is contained in:
a-kizaki
2026-10-28 16:53:31 +09:00
parent 06c1988850
commit fcaf9d4b5f
28 changed files with 10572 additions and 0 deletions

25
answer/Ex05_query.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
// Ex05_query.php
function getJoinData()
{
$dsn = "mysql:host=localhost;dbname=employee_db;charset=utf8";
$username = "rezouser";
$password = "Rezo_0000";
try {
$pdo = new PDO($dsn, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT e.name AS employee_name, d.department_name, p.project_name
FROM employees e
JOIN departments d ON e.dep_id = d.id
JOIN projects p ON e.project_id = p.id";
$stmt = $pdo->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
} catch (PDOException $e) {
return [];
} finally {
$pdo = null;
}
}