Doug Barrett
Doug Barrett

Reputation: 153

PHP PDO execution in a function

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.

Upvotes: -1

Views: 84

Answers (2)

greg0ire
greg0ire

Reputation: 23255

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

Upvotes: 3

N.B.
N.B.

Reputation: 14071

Using table as parameter name is not possible with PDO.

Stack overflow post

php.net post

Upvotes: 1

Related Questions