[development] correct way to update/insert a value in a table

Lluís enboig at gmail.com
Mon Mar 31 12:43:48 UTC 2008

I need to save a value inside a table; I think the best/fast way of doing so is:

    if (!db_query("INSERT INTO {wu_options} (vid, nid, name, value)
                   VALUES (%d, %d, '%s', '%s')",
                   $node->vid, $node->nid, $key, $value))
        db_query("UPDATE {wu_options} SET value = '%s'
                     WHERE vid = %d AND nid = %d AND name LIKE '%s'",
                     $value, $node->vid, $node->nid, $key);

but despite it works, it display an error. Is there any way of hidding
a database error (similar to "@any_function(...) in PHP)? Or any other
way to make drupal try to update a value, and if it don't exists,
create it?


*Envellim quan els records superen les esperances.
*Als llocs desconeguts només s'hi arriba per camins desconeguts.

More information about the development mailing list