問題描述
我知道我需要準備好的語句,因為我在一個腳本中多次調用我的數據庫.
I know that I need prepared statements because I make more than one call to my database during one script.
我想獲得有關以下句子的具體示例
看看類型轉換、驗證和清理變量以及將 PDO 與準備好的語句一起使用.
Look at typecasting, validating and sanitizing variables and using PDO with prepared statements.
我知道他所說的驗證和清理變量是什么意思.但是,我對準備好的語句并不完全確定.我們如何準備報表?通過過濾器,也就是通過消毒?還是通過某些 PDO 層?層的定義是什么?
I know what he mean by validating and sanitizing variables. However, I am not completely sure about prepared statements. How do we prepare statements? By filters, that is by sanitizing? Or by some PDO layer? What is the definition of the layer?
準備好的語句在語句中是什么意思?請舉出具體的例子.
推薦答案
準備好的語句是什么意思聲明?
What do prepared statements mean in the statement?
來自文檔:
此功能允許將重復使用的命令僅解析和計劃一次,而不是每次執行時.
This feature allows commands that will be used repeatedly to be parsed and planned just once, rather than each time they are executed.
參見 pg_prepare
來自上面鏈接頁面的示例:
Example from the page linked above:
<?php
// Connect to a database named "mary"
$dbconn = pg_connect("dbname=mary");
// Prepare a query for execution
$result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1');
// Execute the prepared query. Note that it is not necessary to escape
// the string "Joe's Widgets" in any way
$result = pg_execute($dbconn, "my_query", array("Joe's Widgets"));
// Execute the same prepared query, this time with a different parameter
$result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes"));
?>
用于準備語句的 MySQL 文檔 很好地回答了以下問題:
The MySQL documentation for Prepared Statements nicely answers the following questions:
- 為什么要使用準備好的語句?
- 什么時候應該使用準備好的聲明?
這篇關于如何在 Postgres 中使用準備好的語句的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!