1

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');
2
  • 2
    You need to learn about sql injection attacks. Because your question is suggestive of cargo-cult programming - doing something without ever understanding WHY you're doing it. Commented Oct 26, 2015 at 14:26
  • Thank you everyone. @MarcB: I read your article before. I though I should clear it once again. Commented Oct 26, 2015 at 14:28

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.