您如何阅读以下有关 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 $ c $在第二次迭代中也是如此。 1。
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准备的状态器中的查询
发布评论