了解PHP PG准备的状态器中的查询

编程入门 行业动态 更新时间:2024-10-26 12:25:25
本文介绍了了解PHP PG准备的状态器中的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您如何阅读以下有关 pg_query_params 和 pg_prepare 的代码?

How do you read the following code about pg_query_params and pg_prepare?

$result = pg_query_params ( $dbconn, "SELECT flagged_for_moderator_removal // unsure about Repetition here FROM questions WHERE question_id = $1", array ( $_GET['question_id'] ) ); if ( pg_num_rows ( $result ) == 0 ) { $result = pg_prepare ( $dbconn, "get_flagged_status_list", "SELECT flagged_for_moderator_removal // unsure about Repetition here FROM questions WHERE question_id = $1" ); }

此问题与我的线程在这里我不想声明两次准备好的语句。

This question is related to my thread where I do not want to declare twice the prepared statement.

语句之间的区别是,另一个具有 get_flagged_status_list 名称,而另一个则没有。我了解以下代码

The difference between statements is that the other has a name get_flagged_status_list, while the other one does not. I understand the code as follows

Iteration | 1 2 ---------------------------------------------------------------------- run pg_query_params run pg_qeury_params run pg_prepare run pg_execute run pg_execute

但是,这不是正确的,因为代码运行 pg_prepare

However, this is not true, since the code runs pg_prepare in the second iteration too. 1.

推荐答案

您发布的示例没有意义- pg_prepare()和 pg_query_params()是具有不同目的的独立函数,通常不会结合使用。

Your posted example does not make sense - pg_prepare() and pg_query_params() are independent functions with different purposes that you would not normally use in conjunction.

pg_prepare()准备一条语句(查询),供以后通过 pg_execute()执行。这样做是一种潜在的优化-如果您事先知道您将需要连续执行多次语句,那么预先准备它可以节省数据库服务器上的一些工作,因为它不必(重新)准备

pg_prepare() prepares a statement (a query) for later execution via pg_execute(). This is done as an potential optimization - if you know in advance that you will need to execute the statement many times in a row, preparing it upfront can save some work on the database server, since it does not have to (re-)prepare the statement for each call.

pg_query_params()(以及其简单版本 pg_query())只是直接执行语句(查询),强制数据库服务器在每次调用该函数时(重新)准备该语句。

pg_query_params() (as well as its 'simpler' version pg_query()) just executes the statement (query) directly, forcing the database server to (re)prepare the statement each time the function gets called.

简而言之,这

$result = pg_query_params($query, $params);

将为您提供与此完全相同的结果

will give you the exact same result as this

$statement = pg_prepare($query); $result = pg_execute($statement, $params);

唯一的区别是,在第二种情况下,您仍然具有准备好的语句,可以重复使用 pg_execute()的更多调用-这就是为什么要给它起个名字的原因,因为这样您可以在同一连接上拥有不同的准备好的语句,并可以根据需要执行,以任意顺序多次。

The only difference is that in the second case, you still have the prepared statement, ready to reuse for more calls to pg_execute() - which is why you can give it a name, since that way you can have different prepared statements on the same connection that you can execute as you please, many times, in arbitrary order.

更多推荐

了解PHP PG准备的状态器中的查询

本文发布于:2023-10-25 14:28:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1527219.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   状态   PHP   PG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!