function tripal_insert_db

2.x tripal_insert_db($values, $options = array())

Adds a new database to the Chado DB table and returns the DB object.


$values: An associative array of the values of the db (those to be inserted)

  • name: The name of the database. This name is usually used as the prefix for CV term accessions
  • description: (Optional) A description of the database. By default no description is required.
  • url: (Optional) The URL for the database
  • urlprefix: (Optional) The URL that is to be used as a prefix when constructing a link to a database term

$options: Optional. An associative array of options that can include:

  • update_existing: Set this to '1' to force an update of the database if it already exists. The default is to not update. If the database exists then nothing is added.

Return value

An object populated with fields from the newly added database. If the database already exists it returns the values in the current entry.

Related topics

6 calls to tripal_insert_db()
tripal_cv_load_obo_v1_2 in tripal_cv/includes/
Imports a given OBO file into Chado. This function is usually called by one of three wrapper functions: tripal_cv_load_obo_v1_2_id, tripal_cv_load_obo_v1_2_file or tirpal_cv_load_obo_v1_2_url. But, it can be called directly if the full path to an…
tripal_cv_obo_add_cvterm_dbxref in tripal_cv/includes/
Adds a database reference to a cvterm
tripal_db_add_db in tripal_db/api/
tripal_example_add_dbs in tripal_example/tripal_example.install
Add cvs related to publications
tripal_insert_cvterm in tripal_cv/api/
Add's a controlled vocabulary term to Chado.

... See full list

1 string reference to 'tripal_insert_db'


tripal_db/api/, line 307
Provides an application programming interface (API) to manage references to external databases


function tripal_insert_db($values, $options = array()) {

  // Default Values
  $dbname = $values['name'];
  $description = (isset($values['description'])) ? $values['description'] : '';
  $url = (isset($values['url'])) ? $values['url'] : '';
  $urlprefix = (isset($values['urlprefix'])) ? $values['urlprefix'] : '';
  $update = (isset($options['update_existing'])) ? $options['update_existing'] : TRUE;

  // build the values array for inserting/updating
  $ins_values = array(
    'name' => $dbname,
    'description' => $description,
    'url' => $url,
    'urlprefix' => $urlprefix

  // get the database record if it already exists
  $sel_values = array('name' => $dbname);
  $sel_options = array('statement_name' => 'sel_db_na');
  $result = chado_select_record('db', array('*'), $sel_values, $sel_options);

  // if it does not exists then add it
  if (count($result) == 0) {
    $ins_options = array('statement_name' => 'ins_db_nadeurur');
    $success = chado_insert_record('db', $ins_values, $ins_options);
    if (!$success) {
      tripal_report_error('tripal_db', TRIPAL_WARNING, "Cannot create db '$dbname'.", NULL);
      return 0;
    $result = chado_select_record('db', array('*'), $sel_values, $sel_options);
  // if it exists and update is enabled the do the update
  elseif ($update) {
    $upd_options = array('statement_name' => 'upd_db_nadeurur');
    $success = chado_update_record('db', $sel_values, $ins_values, $upd_options);
    if (!$success) {
      tripal_report_error('tripal_db', TRIPAL_WARNING, "Cannot update db '$dbname'.", NULL);
      return 0;
    $result = chado_select_record('db', array('*'), $sel_values, $sel_options);

  // return the database object
  return $result[0];