Re: multiple fields all unique? [almost solved]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Jas" <jason.gerfen@xxxxxxxxxxxx>

> for instance, say you change the mac and hostname and there is a record
> in the database with the same mac string, how can I flag the field that
> matched from the 3?

Your update will actually fail in the case, so you need to catch the error
with mysql_error() (and maybe mysql_errno()) and examine it to see which
"key" (or index) was matched (a unique column is an index).

When you update the table with an existing "mac" value, the error will be
similar to "Duplicate value for Key XX" where XX is what key was duplicated.
I can't remember if the keys start at zero or one, but your ID column will
be the first key, then mac, hostname, and finally ip (in the order they were
created).

So, if you examine the result of mysql_error() and it say duplicate for key
2, then the "mac" column was duplicated.

Although this sounds a little harder than doing a SELECT prior to and just
comparing values, it lets you do this with just a single query and only have
extra processing upon errors instead of every single update.

If you need a working example, let me know.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux