Re: MySQL Update Quandry
| From: | Matt Monaco | Date: | Fri, 25 Nov 2005 19:54:33 +0000 |
| Subject: | Re: MySQL Update Quandry | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-40728@lists.php.net to get a copy of this message | ||
This might be easier using the mysqli extension, but the function mysql_info
will give you a string result indicating information about the most recent
string, just as you would from the command line.
The rows matched is what you're looking for, which appears first in the
string, so you should fairly easily be able to parse the string for the
first integer (there might even be a function like get_int_value that will
return the integer value of a string based on the first number it finds -
PLEASE SOMEONE EXPAND ON THIS).
But either way, once you've extracted the rows matched from mysql_info your
problem should be solved.
Matt
"maestro" <maestroQC@gmail.com> wrote in message
news:4C.DE.56276.4B357834@pb1.pair.com...
> Greetings,
>
> I am doing an update to a table as such:
>
> class DB {
> ....
>
> function updateMember($email, $password, $postalCode,
> $language, $id, $word) {
>
> ...
> if (!(@ mysql_query($query, $connection))) {
> $this->errors = array(mysql_errno(), mysql_error());
> $error = new Error();
> $error->logError($this->errors);
> return false;
> }
>
> if (mysql_affected_rows() == 0) {
> return false;
> }
>
> return true;
> }
> }
>
>
>
> If the user supplies a wrong $word the mysql_affected_rows will be 0 and
> the method will return false. This is fine.
> My problem arises when the user supplies data that has not changed. The
> mysql_affected_rows will be 0 as well.
> How can I know the difference between an update that fails due to a failed
> where clause and one that updates nothing?
>
> TIA,
> Glenn