function tripal_db_add_db

2.x tripal_db.DEPRECATED.inc tripal_db_add_db($dbname, $description = '', $url = '', $urlprefix = '', $update = 0)
3.x tripal_db.DEPRECATED.inc tripal_db_add_db($dbname, $description = '', $url = '', $urlprefix = '', $update = 0)
1.x tripal_db.api.inc tripal_db_add_db($dbname, $description = '', $url = '', $urlprefix = '', $update = 0)

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

Parameters

$dbname: 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

$update: Optional. 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_db_add_db()
tripal_cv_add_cvterm in tripal_cv/api/tripal_cv.api.inc
Add's a CV term to the cvterm table. If the parent CV does not exist then that too is added to the CV table. If the cvterm is a relationship term then the $is_relationship argument should be set. The function will try to first find theā€¦
tripal_cv_load_obo_v1_2 in tripal_cv/includes/obo_loader.inc
tripal_cv_obo_add_cvterm_dbxref in tripal_cv/includes/obo_loader.inc
Add database reference to cvterm
tripal_featuremap_add_featuremap_dbxref in tripal_featuremap/api/tripal_featuremap.api.inc
tripal_pub_add_pub_dbxref in tripal_pub/api/tripal_pub.api.inc

... See full list

File

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

Code

function tripal_db_add_db($dbname, $description = '', $url = '', 
$urlprefix = '', $update = 0) {

  // 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 = tripal_core_chado_select('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 = tripal_core_chado_insert('db', $ins_values, $ins_options);
    if (!$success) {
      watchdog('tripal_db', "Cannot create db '$dbname'.", NULL, WATCHDOG_WARNING);
      return 0;
    }
    $result = tripal_core_chado_select('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 = tripal_core_chado_update('db', $sel_values, $ins_values, $upd_options);
    if (!$success) {
      watchdog('tripal_db', "Cannot update db '$dbname'.", NULL, WATCHDOG_WARNING);
      return 0;
    }
    $result = tripal_core_chado_select('db', array('*'), $sel_values, $sel_options);
  }

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

}