php - 在 PHP-MySQL 中绑定(bind)变量

标签 php mysql pdo

我使用下面的代码在 PHP 中执行 MySQL 查询。

$cus_id = '1';
$query = new QUERY();
$clause = "SELECT * FROM customers WHERE cus_id=:cus_id AND status='ACTIVE'";
$params = array('cus_id'=>$cus_id);
$result = $query->run($clause, $params)->fetchAll();

现在的问题是:它是否足够安全。或者我还需要绑定(bind)静态字符串吗?像这样的东西:

$clause = "SELECT * FROM customers WHERE cus_id=:cus_id AND status=:status";
$params = array('cus_id'=>$cus_id, 'status'=>'ACTIVE');

最佳答案

它是安全的,因为 ACTIVE 不是用户输入的。所以你不需要绑定(bind)它。

关于php - 在 PHP-MySQL 中绑定(bind)变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348144/

相关文章:

php - 来自数据库的不同 get_rows

mysql - 如果不存在,则插入新行,具体取决于同一表的其他行中的列值

java - fetchLazy 在 jooq 中如何工作?

mysql - 我的 SQL 查询总是报错

php - 其他类(class)的PDO有什么问题?

php - PostgreSQL 中的lastInsertId 总是返回FALSE

windows - 如何注册acpi事件通知?(AcpiInterfaces.RegisterForDeviceNotifications)

php - Facebook 错误 : An error occurred with app. 请稍后再试

php - 在 PHP 循环中连接 CSS 类

php - 直接输入没有搜索关键字的网址时,如何解决错误?