RE: [PHP] error when trying to delete a record
| From: | Jay Blanchard | Date: | Mon, 11 Jul 2005 14:44:21 +0000 |
| Subject: | RE: [PHP] error when trying to delete a record | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-218440@lists.php.net to get a copy of this message | ||
[snip]
Is the above statement true when the id field is numeric (which it
surely is
in this case)? I get the expected results (in mySQL) when using
statements
like
SELECT name FROM table WHERE id=1
with no single quotes round it. Putting quotes round integer values is
counter-intuitive - is it necessary in some cases?
[/snip]
If the id field is numeric and the $id is not set the query will return
a syntax error due to the query being seen as this...
SELECT foo FROM bar WHERE id = ;
The problems multiply when the id field is of the auto-increment type.
Some RDBMS have settings that will allow conditionals, such as WHERE
id=1, to be evaluated as TRUE or FALSE, which accounts for my previous
statement. id, in this case, may be a bad example because most
developers would like a more qualified conditional match before a
deletion occurs. I would never let my development team use the id (or
whatever it was called, especially an auto-increment field) for record
retrieval or deletion. In general you would not have to use quotes
around fields that are INTs, FLOATs, etc.
P.S. Paul, click reply-all when sending messages back to this list. I
know it is counter-intuitive, but it is how this one works.