- <?php defined('SYSPATH') or die('No direct script access.');
- class Musterdb_Database_PDO_Mysql extends Database_PDO
- {
- public function list_tables($like = NULL)
- {
- if (is_string($like))
- {
- // Search for table names
- $result = $this->query(Database::SELECT, 'SHOW TABLES LIKE '.$this->quote($like), FALSE);
- }
- else
- {
- // Find all table names
- $result = $this->query(Database::SELECT, 'SHOW TABLES', FALSE);
- }
- $tables = array();
- foreach ($result as $row)
- {
- $tables[] = reset($row);
- }
- return $tables;
- }
- public function list_columns($table, $like = NULL)
- {
- // Quote the table name
- $table = $this->quote_table($table);
- if (is_string($like))
- {
- // Search for column names
- $result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table.' LIKE '.$this->quote($like), FALSE);
- }
- else
- {
- // Find all column names
- $result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table, FALSE);
- }
- $count = 0;
- $columns = array();
- foreach ($result as $row)
- {
- var_dump($row);
- list($type, $length) = $this->_parse_type($row['Type']);
- $column = $this->datatype($type);
- $column['column_name'] = $row['Field'];
- $column['column_default'] = $row['Default'];
- $column['data_type'] = $type;
- $column['is_nullable'] = ($row['Null'] == 'YES');
- $column['ordinal_position'] = ++$count;
- switch ($column['data_type']) // fixed bug, index was 'type'
- {
- case 'float':
- if (isset($length))
- {
- list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length);
- }
- break;
- case 'string':
- switch ($column['data_type'])
- {
- case 'binary':
- case 'varbinary':
- $column['character_maximum_length'] = $length;
- break;
- case 'char':
- case 'varchar':
- $column['character_maximum_length'] = $length;
- case 'text':
- case 'tinytext':
- case 'mediumtext':
- case 'longtext':
- $column['collation_name'] = $row['Collation'];
- break;
- case 'enum':
- case 'set':
- $column['collation_name'] = $row['Collation'];
- $column['options'] = explode('\',\'', substr($length, 1, -1));
- break;
- }
- break;
- }
- // MySQL attributes
- $column['comment'] = $row['Comment'];
- $column['extra'] = $row['Extra'];
- $column['key'] = $row['Key'];
- $column['privileges'] = $row['Privileges'];
- $columns[$row['Field']] = $column;
- }
- return $columns;
- }
- }