Exemplo n.º 1
0
                           }else if (strrpos($field['Type'], 'date') !== false) {
                               $formField->widget = 'date';*/
                     } else {
                         if (strrpos($field['Type'], 'text') !== false) {
                             $formField->widget = 'textarea';
                         }
                     }
                 }
             }
             //required
             if ($field['Null'] == 'NO') {
                 $formField->required = true;
             } else {
                 $formField->required = false;
             }
             $formField->label = labelTabla($tableName, $field['Field']);
             //primera en mayúscula
             array_push($formFields, $formField);
         }
     }
 }
 //SELECT 2 o TABLAS RELACIONADAS
 $formFieldForeignKey = new FormField();
 $SQLrelated_tableName = "SELECT TABLE_NAME, REFERENCED_TABLE_NAME\n            FROM INFORMATION_SCHEMA.key_column_usage\n            WHERE TABLE_NAME LIKE '%" . $tableName . "_%' AND REFERENCED_TABLE_NAME != '" . $tableName . "' AND CONSTRAINT_SCHEMA LIKE '" . $database . "'";
 //echo "[[$SQLrelated_tableName]]<br /><br />";
 $relatedTableName = "";
 $thirdRelatedTableName = "";
 foreach ($BD->query($SQLrelated_tableName) as $related_table) {
     $relatedTableName = $related_table['TABLE_NAME'];
     $thirdRelatedTableName = $related_table['REFERENCED_TABLE_NAME'];
     //echo "<br /> - Tabla Relacionada: " . $relatedTableName . " --> " . $thirdRelatedTableName . "<br />";
Exemplo n.º 2
0
                }
                $object->count = count($result) / 2;
                array_push($rows, $object);
            }
            $table->rows = $rows;
        }
        //relaciones
        $SQLforeign_tables = "SELECT TABLE_NAME, REFERENCED_TABLE_NAME\n            FROM INFORMATION_SCHEMA.key_column_usage\n            WHERE TABLE_NAME LIKE 'r2_" . $tableName . "_%' AND CONSTRAINT_SCHEMA LIKE '" . $database . "' GROUP BY TABLE_NAME";
        $relations = array();
        foreach ($BD->query($SQLforeign_tables) as $column_name) {
            array_push($relations, $column_name['TABLE_NAME']);
        }
        //array_push($relations, $column_name['TABLE_NAME']);
        $table->relations = $relations;
        //Traer los Nombres de los Campos según la tabla _labels
        foreach ($columns as $key => $value) {
            $labelFinal = labelTabla($tableName, $columns[$key]);
            if ($labelFinal != -1) {
                $columns[$key] = $labelFinal;
            }
        }
        $table->columns = $columns;
        //////////
        echo json_encode($table);
    } else {
        echo "Please Select a Valid Table Name";
    }
} catch (Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
$BD = null;