Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 当结果集(存储过程)为空时获取列名称(Laravel)_Php_Mysql_Laravel 5 - Fatal编程技术网

Php 当结果集(存储过程)为空时获取列名称(Laravel)

Php 当结果集(存储过程)为空时获取列名称(Laravel),php,mysql,laravel-5,Php,Mysql,Laravel 5,我遇到了一种情况,即我的存储过程生成的列是动态的。我想知道,当存储过程返回的结果集在Laravel中为空时,是否有任何方法可以获取结果集的列名 当结果集不为空时,我可以通过迭代轻松访问列,但当数据为空时,是否有方法访问列名 确切地说,这就是我的意思 $data = Schema::getColumnListing("call conflictReport(123,'2016-08-01 09:00:31','2016-08-01 09:00:31')"); 我的过程将3个参数作为in参数 当

我遇到了一种情况,即我的
存储过程生成的列是动态的。我想知道,当存储过程返回的结果集在Laravel中为空时,是否有任何方法可以获取结果集的列名

当结果集不为空时,我可以通过迭代轻松访问列,但当数据为空时,是否有方法访问列名

确切地说,这就是我的意思

 $data = Schema::getColumnListing("call conflictReport(123,'2016-08-01 09:00:31','2016-08-01 09:00:31')");
我的过程将3个参数作为in参数


当结果集为空时,我无法访问列名。我使用的是Laravel的
getColumnListing

下面是如何直接使用PDO来完成它。使用Laravel,您应该能够向我们介绍您的
MySQLConnection
对象的功能

<?php

$pdo = new PDO('mysql:host=localhost;dbname=test', 'root', 'xxxxxxxx');

$stmt = $pdo->query('select * from mytable where false');
$colCount = $stmt->columnCount();
for ($col = 0; $col < $colCount; ++$col) {
    print_r($stmt->getColumnMeta($col));
}
基本上,任何具有结果集的语句都有列元数据


有关更多信息,请参阅。

可能重复
mysql\u fetch\u field
?@mageshkumar使用laravel并通过存储过程调用它。@1000111我使用laravel 5.2在PHP中打印列名时,我与
any混淆了?
。也许你应该用
Laravel 5.2/storage procedure
来替换它。更新了这个问题,基本上我正在使用Laravel访问存储过程。我们使用-->$data=Schema::getColumnListing(“调用conflictReport(123,'2016-08-01 09:00:31','2016-08-01 09:00:31');在laravel to call过程中..虽然我不是laravel用户,但不起作用,但我花了大约5秒钟找到的文档,并看到它以表名作为参数,而不是SQL语句。我认为您应该更仔细地阅读文档。他只是说他需要从存储过程返回列名,而不是从表返回列名。我删除了我的答案。
$stmt = $pdo->query('call myproc()');