一:pdo
提供給預處理語句的參數不需要用引號括起來,驅動程序會自動處理。如果應用程序只使用預處理語句,可以確保不會發生SQL 注入。(然而,如果查詢的其他部分是由未轉義的輸入來構建的,則仍存在 SQL 注入的風險)。
預處理語句如此有用,以至於它們唯一的特性是在驅動程序不支持的時PDO 將模擬處理。這樣可以確保不管數據庫是否具有這樣的功能,都可以確保應用程序可以用相同的數據訪問模式。
?模擬后是否可以防止sql注入
注意:pdo中的dsn區分大小寫,需要用小寫
The PDO connection is case-sensitive, this means that you cannot write
`$PDO = new PDO("MySQL:DBName=dbname;host=localhost");`
You would have to write it
`$PDO = new PDO("mysql:dbname=dbname;host=localhost");`
The difference here is that `mysql` and `dbname` is with all lower-case.
Some IDE's like PHPStorm will show a `TYPO ERROR`, at `dbname` if it's written with lower-case only, this is just to be ignored and have been reported to PHPStorm for them to fix. (Currrent version 10.0.2)
二:
