Difference between drupal_write_record and db_insert I want to know what is the difference between drupal_write_record and db_insert
example :
can i translate that drupal_write_record('MyCustomTable', $Myrecord, $primary_key); to an insert query ?

thank you
drupal_write_record doesn't know by itself whether to do the insert or the update, but this is determined by the existence (or not) of the 3rd parameter: $primary_keys which defaults to array() while db_insert is to insert new record to database.

according to drupal_write_record API documentation


  $primary_keys: To indicate that this is a new record to be inserted, omit this argument. If this is an update, this argument specifies the primary keys' field names. If there is only 1 field in the key, you may pass in a string; if there are multiple fields in the key, pass in an array.


Also 


  Do not use drupal_write_record() within hook_update_N() functions, since the database schema cannot be relied upon when a user is running a series of updates. Instead, use db_insert() or db_update() to save the record.