public function select($table, $options = array(), $bind = "") { $fields = isset($options['fields']) ? $options['fields'] : '*'; if (strrpos($table, "`") === false) { $table = "`{$table}`"; } if (strrpos($fields, "*") === false && strrpos($fields, "`") === false) { $cf = ''; $ex = explode(',', $fields); foreach ($ex as $field) { $fld_tbl = trim(\cx\app\main_functions::get_db_table($field)); $safe_tbl = !empty($fld_tbl) ? "`{$fld_tbl}`." : ''; $cf .= $safe_tbl . '`' . trim(\cx\app\main_functions::get_db_column($field)) . '` , '; } $fields = rtrim($cf, ", "); } $other = isset($options['distinct']) ? 'DISTINCT ' : ''; $other .= isset($options['other']) ? $options['other'] . ' ' : ''; $sql = "SELECT " . $other . $fields . " FROM " . $table . ""; if (isset($options['inner_join'])) { $sql .= " INNER JOIN " . $options['inner_join']; } if (isset($options['natural_join'])) { $sql .= " NATURAL JOIN " . $options['natural_join']; } if (isset($options['left_join'])) { $sql .= " LEFT JOIN " . $options['left_join']; } if (isset($options['on'])) { $sql .= " ON " . $options['on']; } if (isset($options['where'])) { $sql .= " WHERE " . $options['where']; } if (isset($options['group_by'])) { $sql .= " GROUP BY " . $options['group_by']; } if (isset($options['having'])) { $sql .= " HAVING " . $options['having']; } if (isset($options['order_by'])) { $sql .= " ORDER BY " . $options['order_by']; } if (isset($options['limit'])) { $sql .= " LIMIT " . $options['limit']; } if (isset($options['pageinator_limit'])) { $sql .= $options['pageinator_limit']; } if (isset($options['procedure'])) { $sql .= " PROCEDURE " . $options['procedure']; } $sql .= ";"; $fetch_mode = isset($options['fetch']) ? $options['fetch'] : 'all'; return $this->run($sql, $bind, $fetch_mode); }