Reputation: 3800
I am having difficulty updating a table via PHP. Using MySQL prompt or a client app the SQL command works fine, yet when I attempt it in PHP using PDO it fails.
I have taken out the 'desc' field and the PHP script works. I think its getting confused with ASC/DES
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "UPDATE Menu SET name=:name, desc=:desc WHERE id = :id"
$st = $conn->prepare ( $sql );
$st->bindValue( ":id", $this->id, PDO::PARAM_INT );
$st->bindValue( ":name", $this->name, PDO::PARAM_STR );
$st->bindValue( ":desc", $this->name, PDO::PARAM_STR );
$b = $st->execute();
Im pretty sure its just confused from field name to SQL language construct but is there a way of telling the PDO object/prepared statement that desc is a field name ?
i.e something linke
(this does not work by the way)
$sql = "UPDATE Menu SET name=:name, \'desc\'=:desc WHERE id=:id
Upvotes: 0
Views: 108
Reputation: 12889
You have id = 1
, not id = :id
You can't bind to a parameter that doesn't exist.
Also DESC
is a reserved word, you cannot use it without quoting it with backticks.
$sql = "UPDATE `Menu` SET `name`=:name, `desc`=:desc WHERE `id`=:id"
Upvotes: 2