ways to prevent SQL injection

Source: Internet
Author: User

Method 1?? Addslashes ();

Method 2?? Mysql_escape_string ();

Method 3?? Turn on Magic Quotes

Method 4?? Control the data entered by the user, such as:

Using intval to prevent SQL injection, intval () can turn variables into integer types for receiving pure integer data
$id =intval ($_get[' id ');

Method 5?? Use the quote () method of the PDO object to control the data entered by the user:

The quoted string is returned and the special characters in the string are filtered by a backslash escape

Usage: $username =$_post (username);

$username = $pdo->quote ($username);

Method 6?? Use the Prepare (), Excute () method of the PDO object:

Usage:

Placeholder Form 1?? :

$username =$_post (username);

$PASSWD =$_post (passwd);

$sql = "SELECT * from Users where username=: a and passwd=: b ;";

$stmt = $pdo->prepare ($sql);

$stmt->execute (array (:a=>$username,:b=>$passwd));

Placeholder Form 2?? :

$username =$_post (username);

$PASSWD =$_post (passwd);

$sql = "SELECT * from Users where username=? And passwd=? ; ";

$stmt = $pdo->prepare ($sql);

$stmt->execute (array ($username, $passwd));

ways to prevent SQL injection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.