0

I have a question, namely - I have created a function that selects certain things from the base. I passed the function argument as bindParam, but I get an empty array. The only way in this case is to insert a variable from the argument directly into the query without binding. What is the reason for this?

function sampleFunction($test, $test2, $db) {

    $stmt = $db->prepare("SQL QUERY WITH :test AND :test2");
    $stmt->bindParam(':test', $test);
    $stmt->bindParam(':test2', $test2); 
    $stmt->execute();
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
    return $result;

}
sauero
  • 259
  • 2
  • 15
  • What is the actual query? Do you have error reporting on? – chris85 Oct 20 '17 at 10:51
  • No, there is no reason. You should provide a code that supports your claim. [How to create MCVE for a PDO related problem](https://phpdelusions.net/pdo/mcve) – Your Common Sense Oct 20 '17 at 10:51
  • Query is correct, problem is with bindParam as argument of function – sauero Oct 20 '17 at 10:52
  • 1
    there is no such thing as "bindParam as argument of function". bindParam is bindParam, no matter whether it's called inside a function or not. Proceed to create a proof code and you'll see it yourself – Your Common Sense Oct 20 '17 at 10:54
  • @YourCommonSense but according to my reasoning, you are binary from a variable that is specified as a function parameter - so why does not it work? – sauero Oct 20 '17 at 11:02
  • probably your phone changed some words, I can't get what you mean – Your Common Sense Oct 20 '17 at 11:03
  • whatever your reasoning is, you should verify it. Proceed to create a proof code and verify it. It will take you less time than empty argument here in the comments – Your Common Sense Oct 20 '17 at 11:04

0 Answers0