Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "123456";
- $table = "audit_trail";
- $alias = 'aut';
- $db = "Sam04042017";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $db);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $query = "SELECT COLUMN_NAME, DATA_TYPE
- FROM INFORMATION_SCHEMA.COLUMNS
- WHERE TABLE_SCHEMA = 'Sam04042017'
- AND TABLE_NAME = '$table'";
- $result = $conn->query($query);
- $output = '';
- if ($result->num_rows > 0) {
- // output data of each row
- while ($row = $result->fetch_assoc()) {
- $columnName = $row['COLUMN_NAME'];
- $type = getingType($row['DATA_TYPE']);
- $camelizeColumn = $type == 'int' ? camelize($columnName) . 's' : camelize($columnName);
- $templates = '/**' . "\n" . '* Define filtering by '.$alias.'.' . $columnName;
- $templates .= "\n" . '* @param ' . $type . '|' . $type . '[]' . ' ' . '$'.$camelizeColumn;
- $templates .= "\n" . '* @return $this' . "\n" . '*/';
- $templates .= "\n" . 'public function filter' . ucfirst(camelize($columnName)) . '(' . '$'.$camelizeColumn . ')' . "\n {";
- $templates .= "\n\t" . '$this->filterArray(' . "'" . $columnName . "', " . '$'.$camelizeColumn . ');';
- $templates .= "\n\t" . 'return $this;';
- $templates .= "\n" . '}';
- $output .= "\n".$templates;
- }
- }
- print $output;
- $conn->close();
- function camelize($value){
- $value = ucwords(str_replace(array('-', '_'), ' ', $value));
- $value = str_replace(' ', '', $value);
- return lcfirst($value);
- }
- function getingType($dataType)
- {
- if ($dataType == 'int') {
- return 'int';
- } elseif ($dataType == 'decimal') {
- return 'float';
- } elseif ($dataType == 'datetime') {
- return 'datetime';
- }elseif ($dataType == 'varchar') {
- return 'string';
- }elseif ($dataType == 'text') {
- return 'string';
- }elseif ($dataType == 'smallint') {
- return 'int';
- }elseif ($dataType == 'timestamp') {
- return 'datetime';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement