<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