$firstname = 'fred'; $lastname = 'fox';
// Formulate Query
// This is the best way to perform a SQL query
// For more examples, see mysql_real_escape_string()
$query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'",
mysql_real_escape_string($firstname),
mysql_real_escape_string($lastname));
// Perform Query $result = mysql_query($query);
// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
echo $row['firstname'];
echo $row['lastname'];
echo $row['address'];
echo $row['age'];
}
(
http://www.php.net/manual에서 촬영)
요점은 쿼리에 이스케이프 처리되지 않은 표현식을 사용하면 SQL 주입 방법을 제공 할 수 있기 때문입니다.
또한, 특정 쿼리에, 당신이 사이의 SQL 키워드 사용할 수 있습니다 또한 그는 mysql_query가되지 않습니다주의
$q=sprintf("SELECT * FROM comment WHERE time BETWEEN '%s' AND '%s'",
mysql_real_escape_string($prev),
mysql_real_escape_string($time));
을 대신 mysqli_query를 사용하려고합니다.