只是问你们是否可以注意到此代码中的任何 SQL 注入可能性,如果发现请回复。此代码用于从 MySQL 数据库加载简单的“笑话”。谢谢 :)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=website', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$error = '<font color="red"><strong><p align="center">Unable to connect to the database server. Please visit again later!</p></strong></font>';
include 'error.html.php';
exit();
}
try
{
$sql = 'SELECT joketext FROM joke';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = '<font color="red"><strong><p align=center>Error Fetching Jokes</p></strong></font>';
include 'error.html.php';
exit();
}
while ($row = $result->fetch())
{
$jokes[] = $row['joketext'];
}
include 'jokes.html.php'; // Array listing parse
?>
</body>
</html>