Is development using the tb framework still used to prevent SQL injection? How to prevent SQL injection? How can this problem be solved?

Source: Internet
Author: User
Tags how to prevent sql injection
Is development using the tb framework still used to prevent SQL injection? How to prevent SQL injection? Is it possible to prevent SQL injection for tb Framework development? How to prevent SQL injection? How can this problem be solved?

Reply content:

Is development using the tb framework still used to prevent SQL injection? How to prevent SQL injection? How can this problem be solved?

A simple:
To use PDO to operate databases, use placeholder or? in the SQL statement to be executed? Placeholders instead of directly concatenate strings, bindParam is used to bind parameters and specify the parameter type.
A simple example

$ Pdo = new PDO ("mysql: host = $ servername; dbname = myDB", $ username, $ password); // create a new PDO $ pdo-> setAttribute (PDO:: ATTR_ERRMODE, PDO: ERRMODE_EXCEPTION); // the error code $ SQL = 'select * FROM article WHERE id>? ; '; // Use? Placeholder try {$ stmt = $ pdo-> prepare (SQL); // The Returned statment value is assigned to $ stmt-> bindParam (location of the placeholder to be bound, variable [, data type]) to be bound; // bindParam () is the $ stmt method instead of the $ pdo method $ stmt-> execute (); // Execute SQL statement} catch (PDOException $ e) {echo 'execute SQL failed :'. $ e-> getMessage (); exit ();}

Parameterized query using mysqli or pdo

No matter whether you are in the framework or what PDO is related to injection, many people mistakenly understand that PDO can prevent injection and try to prevent it by using percentages and preprocessing, in fact, none of these can play a 100% effect. it is safer to write global filtering and filter out SQL keywords.

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.