#!/usr/bin/php query('SHOW TABLES'); $tables=$r->fetchAll(PDO::FETCH_COLUMN); foreach ($tables as $i => $table) { if (sql_row_obj::table_to_class($table)) { unset($tables[$i]); } } if ($tables) { echo 'Found table(s) without corresponding class: '.implode(', ', $tables)."\n"; if (!prompt_bool('Generate classes for these tables?')) { unset($tables); } } else { echo "No tables found without corresponding classes.\n"; } if (!$tables) { echo 'Which tables should we generate classes for? (space-separated) '; $tables=explode(' ', trim(fgets(STDIN))); if ($tables[0] == '') { echo "Exiting.\n"; exit; } } echo 'Generating classes for table(s): '.implode(', ', $tables)."\n"; foreach ($tables as $table) { $default='sql_'; if (substr($table, -1) == 's') { $default.=substr($table, 0, strlen($table)-1); } else { $default.=$table; } $class=prompt_string('Class name for table '.$table.':', $default); if (substr($class, 0, 4) == 'sql_') { $default=substr($class, 4); } else { $default=$class; } $default.='.php'; $file=SHARED.'/classes/'.prompt_string('Filename for class '.$class.': '.SHARED.'/classes/', $default); if (is_file($file)) { if (!prompt_bool($file.' exists. Overwrite?', false)) { echo 'Skipping table '.$table."\n"; continue; } } echo 'Writing '.$file.'...'; $file=fopen($file, 'w'); fputs($file, "to_php())); fputs($file, "?>\n"); fclose($file); echo "done\n"; } ?>