简体   繁体   English

不使用while循环就将单个postgres记录作为关联数组获取

[英]fetch a single postgres record as an associative array without using while loop

If I have a statement that I know will return only one result: 如果我有一条声明,我知道将仅返回一个结果:

$emp_query = "SELECT * FROM table WHERE id = 'employee_id' LIMIT 1 " $emp_query = "SELECT * FROM table WHERE id = 'employee_id' LIMIT 1

Is there any way I can access the result of pg_query($con, $csr_query); 有什么办法可以访问pg_query($con, $csr_query); as an associative array without using a pg_fetch_assoc and a while loop? 作为关联数组而不使用pg_fetch_assoc和while循环? A while loop seems unnecessary when I know I'm retrieving only one record. 当我知道只检索一条记录时,似乎不需要进行while循环。 Maybe there is some way in PDO as well, I'm just setting it up this way first because I'm more comfortable with the simple way. 也许PDO中也有某种方法,我只是首先以这种方式进行设置,因为我对简单方法更满意。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM