为什么两个功能都使我失败?还是这只是一种幻想?
echo sqlite_escape_string('Hello "World" \'\' ...');
echo "\n";
echo SQLite3::escapeString('Hello "World" \'\' ...');
echo "\n";
?>
输出:
Hello "World" '''' ...
Hello "World" '''' ...
解决方法:
您应该使用PDO来访问数据库,因为它的prepared statements比转义更安全,而且速度更快.
The PHP Data Objects (PDO) extension
defines a lightweight, consistent
interface for accessing databases in
PHP. Each database driver that
implements the PDO interface can
expose database-specific features as
regular extension functions.
使用PDO时的另一个大冒险是,您可以轻松地在数据库之间进行切换(例如MySQL,PostGRESQL和SQLite),而无需更改很多代码.
有关如何使用PDO的快速介绍,可以在nettuts上阅读.如果您问我一个很好的阅读/介绍!
标签:php,sqlite
来源: https://codeday.me/bug/20191010/1888870.html