Instead of manually entering the table names, you could use SHOW TABLES IN [database_name] to get the table names from your database. Once you have the tables stored in an array you can then use SHOW COLUMNS IN [table_name] to retrieve the column names. Once the column names have been stored in another array, you should be able to automate the whole process. This is for MySQL only - for PostgreSQL you would need to query pg_class, pg_attribute and pg_type to get the correct tables, columns and data types.
P.S. the index for your $tables array is slightly wrong - you've used index 5 too many times ...
... like I said, nobody's perfect !! :-)