gpt4 book ai didi

php - 在 PHP 中使用 pg_fetch_row 引用列名

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:34:13 25 4
gpt4 key购买 nike

如何使用 PHP 的 pg_fetch_row 引用列名?

Example关于我们一直在用 Cha 调试的代码。

$dbconn = pg_connect("host=localhost port=5432 dbname=noa user=noa password=123");
$result_titles_tags = pg_prepare( $dbconn, "query777",
"SELECT question_id, title
FROM questions
WHERE question_id IN
(
SELECT question_id
FROM questions
ORDER BY was_sent_at_time
DESC LIMIT 50
)
ORDER BY was_sent_at_time
DESC LIMIT 50;"
);
$result_titles = pg_execute( $dbconn, "query777", array());


while($row = pg_fetch_row( $result_titles )) {
$question_id = $row[0]; // This works but following does not
// We cannot use here `$question_d = $row['question_id']
// Problem here:
// What is the reason that you cannot use $row['question_id']?
// for some unknown reason
//

最佳答案

您正在寻找 pg_fetch_assoc ,它返回一个关联数组——即,您可以按名称调用字段。

pg_fetch_array允许您通过名称或索引来调用它们。 pg_fetch_object允许您将它们称为 $row->question_id

选择您最喜欢的一个。没有真正明显的速度差异。

关于php - 在 PHP 中使用 pg_fetch_row 引用列名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1283579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com