Location: PHPKode > scripts > BlogHelper > common_db.inc
<?
  // common_db.inc
  // Developed by Sam Albarano and Andrew Freed for Senior Design Project


  $dbhost         = "localhost";
  $dbusername     = "root";
  $dbuserpass     = "";
  $default_dbname = "blog";

  $MYSQL_ERRNO = '';
  $MYSQL_ERROR = '';
  
  function db_connect($dbname = "")
  {
    global $dbhost, $dbusername, $dbuserpass, $default_dbname;
    global $MYSQL_ERRNO, $MYSQL_ERROR;

    $link_id = mysql_connect($dbhost, $dbusername, $dbuserpass);
    if(!$link_id)
    {
      $MYSQL_ERRNO = 0;
      $MYSQL_ERROR = "Connection failed to the host $dbhost.";
      return 0;
    }
    else if(empty($dbname) && !mysql_select_db($default_dbname))
    {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
      return 0;
    }
    else if(!empty($dbname) && !mysql_select_db($dbname))
    {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
      return 0;
    }
    else return $link_id;
  }

  function db_select_db($dbname)
  {
    return mysql_select_db($dbname);
  }

  function db_query($result, $db_link=NULL)
  {
    if( empty($db_link) )
      return mysql_query($result);
    else
      return mysql_query($result, $db_link);
  }

  function db_fetch_row($result)
  {
    return mysql_fetch_row($result);
  }

  function db_fetch_array($result)
  {
    return mysql_fetch_array($result);
  }

  function db_num_rows($result)
  {
    return mysql_num_rows($result);
  }

  function db_data_seek($result, $rowNum)
  {
    return mysql_data_seek($result, $rowNum);
  }

  function db_affected_rows($dblink)
  {
    return mysql_affected_rows($dblink);
  }

  function db_close()
  {
    mysql_close();
  }

  function sql_error()
  {
    global $MYSQL_ERRNO, $MYSQL_ERROR;
    if(empty($MYSQL_ERROR))
    {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
    }
    return "$MYSQL_ERRNO: $MYSQL_ERROR";
  }
     
?>
Return current item: BlogHelper