In Laravel 4, is there a way to get the field info based on the results of a query?
I can do this in pure PHP/MySQL, but I'd like to make sure there isn't a way to do this within the Laravel framework before going that route.
Below is an example from PHP's site illustrating the fetch_fields()
function. I'm interested in finding out if there's a Laravel equivalent approach in getting the results from the fetch_fields()
function as in the example below.
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s
", mysqli_connect_error());
exit();
}
$query = "SELECT Name, SurfaceArea from Country ORDER BY Code LIMIT 5";
if ($result = $mysqli->query($query)) {
/* Get field information for all columns */
$finfo = $result->fetch_fields();
foreach ($finfo as $val) {
printf("Name: %s
", $val->name);
printf("Table: %s
", $val->table);
printf("max. Len: %d
", $val->max_length);
printf("Flags: %d
", $val->flags);
printf("Type: %d
", $val->type);
}
$result->close();
}
/* close connection */
$mysqli->close();
?>
Don't know if this is exactly what you want, although it could help. This SO answer How to get database field type in Laravel? mentions using doctrines schema manager:
$schema = DB:: getDoctrineSchemaManager();
Which will then allow you to perform various methods such as the one you mention. See the doctrine documentation for that.
Other than that, the functionality isn't included and you will have to roll your own as far as I know.