I happened to notice last night that db_affected_rows() is the number of matched rows in the WHERE clause, not the number of rows that were actually changed. So (maybe only in drupal) if the data is the same these count as "affected" rows.<br>
<br>If you grep core for db_affected_rows you see that the logic is <br> db_query("UPDATE {variable} SET value = '%s' WHERE name = '%s'",<br> if (!db_affected_rows()) {<br> @db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')",<br>
}<br><br><br>--mark<br><br><div class="gmail_quote">On Mon, Mar 31, 2008 at 9:13 AM, Earnie Boyd <<a href="mailto:earnie@users.sourceforge.net">earnie@users.sourceforge.net</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="Wj3C7c">Quoting John Fiala <<a href="mailto:jcfiala@gmail.com">jcfiala@gmail.com</a>>:<br>
<br>
> On Mon, Mar 31, 2008 at 6:43 AM, Lluís <<a href="mailto:enboig@gmail.com">enboig@gmail.com</a>> wrote:<br>
>> I need to save a value inside a table; I think the best/fast way of<br>
>> doing so is:<br>
>><br>
><br>
> Personally I like to keep track internally if a row's been saved to<br>
> the db or not - but I've seen some folks try the UPDATE statement,<br>
> call db_affected_rows to see if any rows were changed, and if none<br>
> were, to do the insert.<br>
<br>
</div></div>Doesn't work if data is the same; no rows will be updated and<br>
db_affected_rows will return 0. The method the OP used is correct<br>
insert else update.<br>
<div><div></div><div class="Wj3C7c"><br>
Earnie -- <a href="http://for-my-kids.com/" target="_blank">http://for-my-kids.com/</a><br>
-- <a href="http://give-me-an-offer.com/" target="_blank">http://give-me-an-offer.com/</a><br>
<br>
</div></div></blockquote></div><br>