简体   繁体   中英

Bind variables in PHP-MySQL

I am using below code to execute MySQL query in PHP .

$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();

Now the question is: is it secure enough. Or do I need to bind the static String as well? Something like:

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

It's secure because ACTIVE isn't user input. So you don't need to bind it.

It's fine the way you have it. The value for status isn't being dynamically assembled and doesn't create any vulnerabilities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM