PDO処理

背景
投稿者投稿者kazuyaいいね0お気に入り登録1
プレイ回数103難易度(4.1) 613打 英語
PDO処理
PHPの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();

(})

}

(?>)

?>