【发布时间】:2016-08-04 19:44:29
【问题描述】:
这个查询对 sql 注入安全吗?
并且必须在每个函数中编写 $connection->close();?
function insert_mytable() {
global $connection;
$text = 'bla bla';
$hashtag = 'bla bla';
// Prepare the statement
$stmt = $connection->prepare("INSERT INTO my_table (text, hashtag) VALUES (?, ?)");
$stmt->bind_param('ss', $text, $hashtag);
// Execute the statement
$stmt->execute();
// Close the statement
$stmt->close();
$connection->close();
}
【问题讨论】:
-
不需要关闭连接,如果您在每次查询后都这样做会适得其反。
-
顺便说一句...
$connection未定义。