PDO処理
関連タイピング
問題文
(<?php)
<?php
(require_once '\xampp\db_config.php';)
require_once '\xampp\db_config.php';
($dbh=new PDO('mysql:host=localhost;dbname=db1',$user,$pass);)
$dbh=new PDO('mysql:host=localhost;dbname=db1',$user,$pass);
(try{)
try{
(if(empty($_GET['id'])) throw new Exception('Error');)
if(empty($_GET['id'])) throw new Exception('Error');
($id=(int) $_GET['id'];)
$id=(int) $_GET['id'];
($dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);)
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
($dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);)
$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
($sql="SELECT * FROM recipes WHERE id = ?";)
$sql="SELECT * FROM recipes WHERE id = ?";
($stmt=$dbh->prepare($sql);)
$stmt=$dbh->prepare($sql);
($stmt->bindValue(1,$id,PDO::PARAM_INT);)
$stmt->bindValue(1,$id,PDO::PARAM_INT);
($stmt->execute();)
$stmt->execute();
($result=$stmt->fetch(PDO::FETCH_ASSOC);)
$result=$stmt->fetch(PDO::FETCH_ASSOC);
($dbh=null;)
$dbh=null;
(echo "<a href='index.php'>toppage</a>";)
echo "<a href='index.php'>toppage</a>";
(}catch(Exception $e){)
}catch(Exception $e){
(echo "Error" . htmlspecialchars($e->getMessage(),ENT_QUOTES,'UTF-8') . "<br>";)
echo "Error" . htmlspecialchars($e->getMessage(),ENT_QUOTES,'UTF-8') . "<br>";
(die();)
die();
(})
}
(?>)
?>