Using PDO_Mysql extension in PHP effectively avoids SQL Injection

Source: Internet
Author: User

First, what is SQL injection?
To put it bluntly, when a person accesses your application, he needs to enter some special characters, you didn't filter the input. As a result, his input changes the function of your SQL statement to achieve his own purpose. In this way, he may have a lot of permissions, to launch your own attacks
The above description is not rigorous. If you want to learn more about SQL injection, visit the following link:
 
Http://www.php.net/manual/zh/security.database.sql-injection.php
 
The purpose of this article is not to let everyone know what SQL injection is, but to forget SQL injection.
In practice, there must be a lot of experience to be summarized to avoid SQL injection. In the previous mysql and mysqli extensions, We need to manually process user input data to avoid SQL injection, at this time, you must have a good understanding of SQL injection. Only by understanding it can you take effective measures for specific injection methods.
 
The emergence of PDO_Mysql allows you to get away from the struggle of SQL injection. You just need to remember to set up a suitable charset when creating a pdo_mysql linked instance, you no longer have to worry about SQL injection. It is very important to set the character set correctly. Otherwise, some special characters can be constructed for SQL injection.
 
Mysql: host = localhost; dbname = testdb; charset = utf8
 
Prepare before SQL statement execution
 
Well, it seems that this is so simple that we say goodbye to SQL injection, and it feels a bit illusory.

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.