public function fetchKeysValues($key, $value)
 {
     $query = data::select($key . ', ' . $value, $this->tableName, $this->where, $this->order, $this->limit);
     //data::debug();
     $array = array();
     while ($r = mysql_fetch_object($query)) {
         $array[$r->{$key}] = $r->{$value};
     }
     return $array;
 }
Beispiel #2
0
 public function createComponentFromTable($tableName)
 {
     $return = NULL;
     $count = data::select('COUNT(*) AS TOTAL', $tableName, NULL, NULL, 1) or $return = false;
     $count = $count->fetch();
     if ($count['TOTAL'] == 0) {
         data::insert($tableName, array('id'), array(1));
     }
     //TODO: Fix ID for primary key.
     $result = data::select('*', $tableName, NULL, NULL, 1) or $return = false;
     if ($return === false) {
         return false;
     }
     $total = $result->columnCount();
     $fields = array();
     for ($x = 0; $x < $total; $x++) {
         $meta = $result->getColumnMeta($x);
         //var_export($meta); echo "------------------<br />\n";
         $type = in_array('primary_key', $meta['flags']) ? 'id' : $this->getTypeFromMeta($meta, $tableName, $meta['name']);
         array_push($fields, new Field($meta['name'], $type));
     }
     if ($count['TOTAL'] == 0) {
         data::delete($tableName);
     }
     $newComponent = new cmp_interface($tableName, new fieldSet($fields));
     $newComponent->name = $tableName;
     return $newComponent;
 }