Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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从表中查找列名称_Php_Sql - Fatal编程技术网

如何使用php从表中查找列名称

如何使用php从表中查找列名称,php,sql,Php,Sql,有人知道如何在php中找到所选表的列名吗 Exmaple: 如果我有以下表格,请致电客户: cust_id cust_name cust_age 1 Alan 35 2 Alex 52 3 Amy 15 当我选择customer表时,它将返回值cust_id、cust_name和cust_age,如何仅在php中获取列名 您可以使用SQL:SHOW COLUMNS FROM

有人知道如何在php中找到所选表的列名吗

Exmaple: 如果我有以下表格,请致电客户:

cust_id    cust_name   cust_age
1          Alan        35      
2          Alex        52
3          Amy         15

当我选择customer表时,它将返回值cust_id、cust_name和cust_age,如何仅在php中获取列名

您可以使用SQL:SHOW COLUMNS FROM customer;或描述客户

或者使用-后者更具可移植性

如果您的数据库是MySQL,那么您可以在php中使用MySQL\u field\u name和MySQL\u fetch\u field函数

$res = mysql_query('select * from customer', $link);

echo mysql_field_name($res, 0); // print cust_id
echo mysql_field_name($res, 1); // print cust_name 
echo mysql_field_name($res, 2); // print cust_age
你可以查一下

如果您想要字段的其他信息,请检查此项

在PHP mysql\u fetch\u字段中,mysql\u字段\u名称将对您有所帮助,我猜你是指MySQL?除了编程语言外,一定要具体说明你的数据库。。但错误消息显示:警告:mysql\u字段\u名称:提供的资源不是有效的mysql结果resource@JinYong:试试这个->$res=mysql_查询'select*fromcustomer';我尝试了mysql_查询'select*from customer'和mysql_查询'select*from customer',$link。相同的错误显示..: