I want, for my form in php, a result including columntype. Is there a way to make a query and including the column type?
select * from TableA
+
SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'yourTableName'
I want, for my form in php, a result including columntype. Is there a way to make a query and including the column type?
select * from TableA
+
SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'yourTableName'
There's probably no way to select both data and column type because the column type is typically stored in a separate table (this would depend on the database). For example, in MySql:
Query to column type: SELECT COLUMN_NAME,DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TableA'
You would then to need to parse the results of the 2 queries and join them using php (I don't think there's an easy way to do this using SQL because you would be joining a 1xN results with a Nx1 result).
More info about where the column type is stored: http://dev.mysql.com/doc/refman/5.7/en/information-schema.html
Those are inherently different data sets so I bet you'd need to write a possibly rather messy stored routine.
You don't explain why you need it but I suspect you'll be fine with the column types of the result set (rather than the source tables). That will include exactly the same information plus the type of calculated columns.
The exact mechanism depends on your DBMS and database library. You don't give any clue about that but your sample code looks like MySQL so the options include:
If you want to stick to your original spec, at least save yourself some trouble and just run two queries.
I found this. So now i can combine the array!
$i = 0;
while ($column = $query->getColumnMeta($i++)) {
print_r($column);
}