예제 #1
0
        print "</li>";
    }
}
//
// PostgreSQL functions
//
if ($f_pg_connect == 1) {
    print "<li>Depends on: PostgreSQL - OK \n";
    if (!($config_loaded && $CONF['database_type'] == 'pgsql')) {
        print "<br>(change the database_type to 'pgsql' in config.inc.php if you want to use PostgreSQL)\n";
    }
    print "</li>";
}
if ($f_sqlite_open == 1) {
    print "<li>Depends on: SQLite - OK \n";
    if (!($config_loaded && db_sqlite())) {
        print "<br>(change the database_type to 'sqlite' in config.inc.php if you want to use SQLite)\n";
    }
    print "</li>";
}
//
// Database connection
//
if ($config_loaded) {
    list($link, $error_text) = db_connect(TRUE);
    if ($error_text == "") {
        print "<li>Testing database connection - OK - {$CONF['database_type']}://{$CONF['database_user']}:xxxxx@{$CONF['database_host']}/{$CONF['database_name']}</li>";
    } else {
        print "<li><b>Error: Can't connect to database</b><br />\n";
        print "Please edit the \$CONF['database_*'] parameters in config.inc.php.\n";
        print "{$error_text}</li>\n";
예제 #2
0
 /**
  * build_select_query
  *
  * helper function to build the inner part of the select query
  * can be used by read_from_db() and for generating the pagebrowser
  *
  * @param array or string - condition (an array will be AND'ed using db_where_clause, a string will be directly used)
  *                          (if you use a string, make sure it is correctly escaped!)
  *                        - WARNING: will be changed to array only in the future, with an option to include a raw string inside the array
  * @param array searchmode - operators to use (=, <, >) if $condition is an array. Defaults to = if not specified for a field.
  * @return array - contains query parts
  */
 protected function build_select_query($condition, $searchmode)
 {
     $select_cols = array();
     $yes = escape_string(Config::lang('YES'));
     $no = escape_string(Config::lang('NO'));
     if (db_pgsql()) {
         $formatted_date = "TO_DATE(text(###KEY###), '" . escape_string(Config::Lang('dateformat_pgsql')) . "')";
         $base64_decode = "DECODE(###KEY###, 'base64')";
     } elseif (db_sqlite()) {
         $formatted_date = "strftime(###KEY###, '" . escape_string(Config::Lang('dateformat_mysql')) . "')";
         $base64_decode = "base64_decode(###KEY###)";
     } else {
         $formatted_date = "DATE_FORMAT(###KEY###, '" . escape_string(Config::Lang('dateformat_mysql')) . "')";
         $base64_decode = "FROM_BASE64(###KEY###)";
     }
     $colformat = array('ts' => "{$formatted_date} AS ###KEY###, ###KEY### AS _###KEY###", 'bool' => "CASE ###KEY### WHEN '" . db_get_boolean(true) . "' THEN '1'    WHEN '" . db_get_boolean(false) . "' THEN '0'   END as ###KEY###," . "CASE ###KEY### WHEN '" . db_get_boolean(true) . "' THEN '{$yes}' WHEN '" . db_get_boolean(false) . "' THEN '{$no}' END as _###KEY###", 'b64p' => "{$base64_decode} AS ###KEY###");
     # get list of fields to display
     $extrafrom = "";
     foreach ($this->struct as $key => $row) {
         if (($row['display_in_list'] != 0 || $row['display_in_form'] != 0) && $row['not_in_db'] == 0) {
             if ($row['select'] != '') {
                 $key = $row['select'];
             }
             if ($row['extrafrom'] != '') {
                 $extrafrom = $extrafrom . " " . $row['extrafrom'] . "\n";
             }
             if (isset($colformat[$row['type']])) {
                 $select_cols[] = str_replace('###KEY###', $key, $colformat[$row['type']]);
             } else {
                 $select_cols[] = $key;
             }
         }
     }
     $cols = join(',', $select_cols);
     $table = table_by_key($this->db_table);
     $additional_where = '';
     if ($this->domain_field != "") {
         $additional_where .= " AND " . db_in_clause($this->domain_field, $this->allowed_domains);
     }
     # if logged in as user, restrict to the items the user is allowed to see
     if (!$this->is_admin && $this->user_field != '') {
         $additional_where .= " AND " . $this->user_field . " = '" . escape_string($this->username) . "' ";
     }
     if (is_array($condition)) {
         if (isset($condition['_']) && count($this->searchfields) > 0) {
             $simple_search = array();
             foreach ($this->searchfields as $field) {
                 $simple_search[] = "{$field} LIKE '%" . escape_string($condition['_']) . "%'";
             }
             $additional_where .= " AND ( " . join(" OR ", $simple_search) . " ) ";
             unset($condition['_']);
         }
         $where = db_where_clause($condition, $this->struct, $additional_where, $searchmode);
     } else {
         if ($condition == "") {
             $condition = '1=1';
         }
         $where = " WHERE ( {$condition} ) {$additional_where}";
     }
     return array('select_cols' => " SELECT {$cols} ", 'from_where_order' => " FROM {$table} {$extrafrom} {$where} ORDER BY " . $this->order_by);
 }
예제 #3
0
function _drop_index($table, $index)
{
    global $CONF;
    $table = table_by_key($table);
    if ($CONF['database_type'] == 'mysql' || $CONF['database_type'] == 'mysqli') {
        return "ALTER TABLE {$table} DROP INDEX {$index}";
    } elseif ($CONF['database_type'] == 'pgsql' || db_sqlite()) {
        return "DROP INDEX {$index}";
        # Index names are unique with a DB for PostgreSQL
    } else {
        echo "Sorry, unsupported database type " . $conf['database_type'];
        exit;
    }
}