0

I've created this class:

class  data
{
public function del($cat, $id)
{
    global $dbh;

    $del = $dbh->prepare("DELETE FROM :cat WHERE id = :id");
    $del->bindParam(":cat",$cat);
    $del->bindParam(":id", $id);
    $del->execute();
}
}

And I'm running into an issue with binding the

:cat

variable to the statement, if I don't use bindParam for

:cat

and just tell it which table I want it to delete it from, for example:

$del = $dbh->prepare("DELETE FROM table1 WHERE id = :id");

It works fine.

I know it has to be some stupid error, but I can't for the life of me figure it out.

Doug Barrett
  • 135
  • 1
  • 2
  • 9

2 Answers2

3

It seems what you're trying to do is simply not possible

Community
  • 1
  • 1
greg0ire
  • 22,714
  • 16
  • 72
  • 101
1

Using table as parameter name is not possible with PDO.

Stack overflow post

php.net post

Community
  • 1
  • 1
N.B.
  • 13,688
  • 3
  • 45
  • 55