Prepared Statement

Prepared Statement

Ein Prepared Statement ist eine sogenannte vorbereitete Anweisung für ein Datenbanksystem. Im Gegensatz zu gewöhnlichen Statements enthält es noch keine Parameterwerte. Statt dessen werden dem Datenbanksystem Platzhalter übergeben.

Mittels Prepared Statements können SQL-Injections effektiv verhindert werden, da das Datenbanksystem die Gültigkeit von Parametern prüft, bevor diese verarbeitet werden.

Soll ein Statement mit unterschiedlichen Parametern mehrere Male (z. B. innerhalb einer Schleife) auf dem Datenbanksystem ausgeführt werden, können Prepared Statements einen Geschwindigkeitsvorteil bringen, da das Statement schon vorübersetzt im Datenbanksystem vorliegt und nur noch mit den neuen Parametern ausgeführt werden muss.

Beispiel eines Prepared Statement in Java:

PreparedStatement ps = Connection.prepareStatement(
    "SELECT user, password FROM tbl_user WHERE (user=?)"
); // Statement wird erzeugt
ps.setString(1, username); // Parameter werden übergeben
ResultSet rs = ps.executeQuery(); //Statement wird ausgeführt.

Beispiel eines Prepared Statement in PHP mit PHP Data Objects[1]:

<?php
$stmt = $dbh->prepare("SELECT user, password FROM tbl_user WHERE (user=:user)");
$stmt->bindParam(':user', $user);
 
// eine Zeile abfragen
$user = 'Alice';
$stmt->execute();
 
// eine weitere Zeile mit anderen Werten abfragen
$user = 'Bob';
$stmt->execute();
?>

Weblinks

Einzelnachweise

  1. Prepared Statements und Stored Procedures. Abgerufen am 25. September 2011.

Wikimedia Foundation.

Игры ⚽ Поможем написать реферат

Schlagen Sie auch in anderen Wörterbüchern nach:

  • prepared — adjective 1 be prepared to do sth to be willing to do something, especially something difficult or something that you do not usually do: You have to be prepared to take risks in this kind of work. | How much is she prepared to pay? 2 I m not… …   Longman dictionary of contemporary English

  • prepared — pre|pared S2 [prıˈpeəd US ˈperd] adj ▬▬▬▬▬▬▬ 1 be prepared to do something 2¦(ready to deal with something)¦ 3 I m not prepared to do something 4¦(made earlier)¦ ▬▬▬▬▬▬▬ 1.) be prepared to do sth to be willing to do something, especially… …   Dictionary of contemporary English

  • prepared — pre|pared [ prı perd ] adjective 1. ) ready and able to do something: prepared for: We have to be prepared for any eventuality. well/fully prepared: She will need to be well prepared for the job ahead. ill/badly prepared: The Premier seemed ill… …   Usage of the words and phrases in modern English

  • prepared — UK [prɪˈpeə(r)d] / US [prɪˈperd] adjective 1) ready and able to do something prepared for: We have to be prepared for any eventuality. well/fully prepared: She will need to be well prepared for the task ahead. ill/badly prepared: The Premier… …   English dictionary

  • statement — 01. An aide read a prepared [statement] saying that the President would not be answering any questions until he received further information. 02. All general [statements] are false. 03. Our recent financial [statement] shows that we are doing… …   Grammatical examples in English

  • prepared — [[t]prɪpe͟ə(r)d[/t]] ♦♦ 1) ADJ: v link ADJ to inf If you are prepared to do something, you are willing to do it if necessary. Are you prepared to take industrial action?... Members of the KGB service were only prepared to take orders from the… …   English dictionary

  • prepared — [prɪˈpeəd] adj 1) ready and able to do something Ant: unprepared We have to be prepared for anything.[/ex] 2) ready for use Make sure the room is prepared before they get there.[/ex] 3) done or made earlier Bonner read from a prepared… …   Dictionary for writing and speaking English

  • prepared — adjective 1. made ready or fit or suitable beforehand (Freq. 14) a prepared statement be prepared for emergencies • Ant: ↑unprepared • Similar to: ↑braced, ↑embattled, ↑ …   Useful english dictionary

  • statement — state·ment n 1 a: an official or formal report or declaration a statement of policy b: an oral or written assertion (as by a witness) or conduct intended as an assertion see also hearsay, prior consistent statement …   Law dictionary

  • statement of affairs — ˌstatement of afˈfairs noun statements of affairs PLURALFORM [countable] ACCOUNTING LAW a document showing a company s assets and liabilities at a certain date. A statement of affairs is usually prepared when a company is about to go bankrupt * * …   Financial and business terms

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”