我有一个postgresql数据库,我通过php连接并读取数据库。我已经把php代码放到了我的代码所传递的查询结果中。通过PHP获取数据库的列名(s)
EX-我的代码:(注 - 我的HTML网页使用了数据库请求输入并搜索给定的输入形式)
<?php
$result = pg_prepare($dbh, "Query1", 'SELECT * FROM test.bact WHERE disease = $1');
$result = pg_execute($dbh, "Query1", array($disease));
if (!$result) {
die("Error in SQL query: " . pg_last_error());
}
//$rows = pg_fetch_all($result)
/*// iterate over result set
// print each row*/
while ($row = pg_fetch_array($result)) {
echo $row[0]." ".$row[1]. "<br />";
}
从上面的代码,我得到我的信息我想在IE与列名更有组织的形式获取的数据 - 串一个空格(echo $row[0]." ".$row[1]
)
example: Information at row[0]<space>Information at row[1]
我想要的分离。 究竟应该如何样子 -
Name of Column : Data
Name of column : Data ...and so on.
我知道有使用mysql_fetch_field
在MySQL的方式,但我想要的东西PostgreSQL的。由于我是php n数据库的新手,我不确定如何使用它。
任何帮助,将不胜感激。
尝试'pg_fetch_assoc()'代替http://php.net/manual/en/function.pg-fetch-assoc.php – Waygood 2013-04-22 14:23:19
然后,您可以使用'array_keys() '在一行中,列名为 – Waygood 2013-04-22 14:27:15
使用'pg_fetch_assoc' +'array_keys' – 2013-04-22 14:32:40