0

Im trying to write an update query with PDO but it's not work

for ($count = 0; $count < 4; $count++) {
        if (!trim($elements[$count])=='') {

                $query = "update servers set " . '?' . "=" . '?' . "where " . '?'  . "=" . '?';
                $pdo = new PDO($db->dsn, 'adp', 'pass');
                $stmt = $pdo->prepare($query);
                $stmt->bindParam(1, $index[$count]);
                $stmt->bindParam(2, $elements[$count]);
                $stmt->bindParam(3, $index[$count]);
                $stmt->bindParam(4, $ServerName);
                $stmt->execute();
          }
}
4
  • What doesn't work? Any errors, notices, ... something? Commented Sep 23, 2014 at 11:21
  • 3
    add field name in your query Commented Sep 23, 2014 at 11:21
  • 1
    you can't use parameters (i.e. ?) as field names. Commented Sep 23, 2014 at 11:24
  • May be possible duplicate of stackoverflow.com/questions/16885091/… Commented Sep 23, 2014 at 11:36

1 Answer 1

1

Table and Column names cannot be replaced by parameters in PDO. See this answer for more details.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.