I can get the column names for a table but is there a way to retrieve the default data value for each column?
Here is what I'm using to get the tables column names:
$q = $dbh->query("DESCRIBE tablename");
$table_fields = $q->fetchAll(PDO::FETCH_COLUMN);
print_r($table_fields);
This prints an array of column names, but I'm trying to get the default data value for each column name also.
Another option is to go to the data dictionary and find the value in Information_Schema.Columns
. This allows you to limit results to a single column.
$query = <<< endsql
SELECT Column_Default
FROM Information_Schema.Columns
WHERE Table_Schema = '$yourSchema'
AND Table_Name = '$yourTableName'
AND Column_Name = '$yourColumnName'
endsql;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With