I have a weird issue which I’m sure is because I don’t understand all the idiosyncrasies of MySQL 🙁
I have a table with a column that has the default value of NULL, “TeamID”. When I add a new row without giving a value for that column, it is NULL. Perfect. Except when I wish to update that row, the following code doesn’t seem to change the value from NULL (or even cause any error):
$STH = $this->_db->prepare("UPDATE UserDetails SET
TeamID = ':teamID' WHERE UserID = ':userID';");
$STH->execute($params);
To restate the problem: I have a problem overwriting TeamID with a non-nullable value if it’s already NULL. I can’t see where there’s any error in the code itself, so I’m imagining it’s something to do with the NULL value.
One problem coding with PHP/MySQL is that you can’t step through your code and look at the contents of the database at the same time — because PHPMyAdmin gets stepped through, too.
Thanks for any help!
Part of your problem may lie in using quote marks around the parameters. Since you’re using a PDO prepared statement with params, you don’t have to quote your strings. I’m not sure how PDO represents
null, but you might end up in a situation where you try to setSET TeamID = ''orSET TeamID = 'null'and, depending on the column type, that may not be valid.