In Laravel 4, is there a way to get the field info based on the results of a query?
在Laravel 4中,有没有办法根据查询结果获取字段信息?
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.
我可以在纯PHP / MySQL中执行此操作,但我想确保在执行该路由之前没有办法在Laravel框架内执行此操作。
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网站上的一个示例,说明了fetch_fields()函数。我有兴趣了解是否有一个Laravel等效方法来获取fetch_fields()函数的结果,如下例所示。
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", 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\n", $val->name);
printf("Table: %s\n", $val->table);
printf("max. Len: %d\n", $val->max_length);
printf("Flags: %d\n", $val->flags);
printf("Type: %d\n\n", $val->type);
}
$result->close();
}
/* close connection */
$mysqli->close();
?>
1 个解决方案
#1
0
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:
不知道这是否正是你想要的,虽然它可能有所帮助。这个SO答案如何在Laravel中获取数据库字段类型?提到使用doctrines架构管理器:
$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.
除此之外,功能不包括在内,据我所知,你必须自己动手。
#1
0
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:
不知道这是否正是你想要的,虽然它可能有所帮助。这个SO答案如何在Laravel中获取数据库字段类型?提到使用doctrines架构管理器:
$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.
除此之外,功能不包括在内,据我所知,你必须自己动手。