msqli_* prevent SQL injection

本文介绍了如何使用PHP的mysqli扩展及预处理语句来避免代码中的SQL注入风险。通过具体的SELECT和INSERT语句示例,展示了如何绑定参数并执行安全的SQL操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

To avoid your code be vulnerable, especially for preventing SQL injection. You may need the mysqli_* function and prepare statement of it to make it.

I will make some examples, such like this:

  • The SELECT sentence like this:
$stmt = $conn->prepare('SELECT column_name FROM table_name WHERE column_name = ?');
$stmt->bind_param('s', $varname);
$stmt->execute();
$result = $stmt->get_result();
  • The INSERT sentence like this:
$stmt = $conn->prepare('INSERT INTO table_name(column_name_f, column_name_s) VALUES(?,?)');
$stmt->bind_param('ss', $var_name_f, $var_name_s);
$stmt->execute();
$stmt->close();

So the only question you guys want to know is that mysterious ‘s’.
Not other mean, just String.

And other’s just as the word the said.
- bind_param which bind param like $var_name_f with the first question mark in this string(’s’) format.
- execute means that the statement will execute the sql sentence.
- close, just close connection;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值