Mic*_*bel 2 mysql sql erlang sql-injection
我对erlang很新,我需要编写一些在MySQL数据库中插入行的代码.如何使用Erlang阻止SQL注入?是否还有其他语言的准备语句或我应该怎么做?
谢谢你的回复.
这个答案取决于您使用的驱动程序.
Erlang ODBC有一个函数param_query,它将一组参数绑定到查询,它也可以转义所有SQL特殊字符.
erlang-mysql-driver准备了语句:
%% Register a prepared statement
mysql:prepare(update_developer_country,
<<"UPDATE developer SET country=? where name like ?">>),
%% Execute the prepared statement
mysql:execute(p1, update_developer_country, [<<"Sweden">>,<<"%Wiger">>]),
Run Code Online (Sandbox Code Playgroud)
(来自Yariv博客的代码)
作为最后的手段,你总是可以逃脱角色
NUL (0x00) --> \0
BS (0x08) --> \b
TAB (0x09) --> \t
LF (0x0a) --> \n
CR (0x0d) --> \r
SUB (0x1a) --> \z
" (0x22) --> \"
% (0x25) --> \%
' (0x27) --> \'
\ (0x5c) --> \\
_ (0x5f) --> \_
Run Code Online (Sandbox Code Playgroud)