SQL ( ):
name = form_params["name"]
year = 2011
sql = "INSERT INTO Students (name, year) " +
"VALUES ('" + name + "', " + year + ");"
database_handle.query(sql)
year , , ; - .
name , . Bobby Tables :
name = "Robert'); DROP TABLE Students;
INSERT INTO Students (name, year) VALUES ('Robert');
DROP TABLE Students;
.
- , , . , . -- , .
, - .
:
name = form_params["name"].regex_replace("'", "\\\\'")
, , . "\\\\'" \\'. regex_replace \'.
... VALUES ('Robert\'); DROP TABLE Students; -- ', 2011);
.
. , , \\ \, \\ \ ( $1 \1 ) ,
... VALUES ('Robert\\'); DROP TABLE Students;
SQL- .
, , , , , , . :
, , , , :
sql = "... '" + database_handle.escape(name) + "' ..."
( ), , :
sql = "... VALUES (:n, :y);"
database_handle.query(sql, n = name, y = year)