PDO prevent SQL injection in detail

Source: Internet
Author: User

<span style= "FONT-SIZE:18PX;" ><?PHP$DBH = new PDO ("Mysql:host=localhost; Dbname=demo "," User "," pass "), $dbh->setattribute (Pdo::attr_emulate_prepares, false); Disables the emulation effect of the prepared statements $dbh->exec ("Set names ' UTF8 '"); $sql = "SELECT * from test where name =? and password =? ";    can also be used: neme this form $stmt = $dbh->prepare ($sql); $exeres = $stmt->execute (Array ($testname, $pass)); if ($exeres) {while ($row = $stmt->fetch (PDO::FETCH_ASSOC)) {    print_r ($row)}} $DBH = null;//: When prepare () is called, the query statement has been sent to the database server, where there are only placeholders? Send in the past, no user submitted data, when called to execute (), the user submitted values will be sent to the database, they are separate transmission, the two independent, SQL attackers do not have a chance. But we need to be aware of the following situations, PDO does not help you to prevent SQL injection 1, you can not let the placeholder? Instead of a set of values, such as: SELECT * from the blog WHERE userid in (?); 2. You cannot allow placeholders to replace data table or column names, such as: SELECT * from blog ORDER by?; 3. You can't make a placeholder? Instead of any other SQL syntax, such as: SELECT EXTRACT (? From Datetime_column) as variable_datetime_element from blog;</span>

PDO prevent SQL injection in detail

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.