PDOStatement::bindParam

(PHP 5 >= 5.1.0, PHP 7, PHP 8, PECL pdo >= 0.1.0)

PDOStatement::bindParam Binds a parameter to the specified variable name

Beschreibung

public PDOStatement::bindParam(
    string|int $param,
    mixed &$var,
    int $type = PDO::PARAM_STR,
    int $maxLength = 0,
    mixed $driverOptions = null
): bool

Binds a PHP variable to a corresponding named or question mark placeholder in the SQL statement that was used to prepare the statement. Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.

Most parameters are input parameters, that is, parameters that are used in a read-only fashion to build up the query (but may nonetheless be cast according to type). Some drivers support the invocation of stored procedures that return data as output parameters, and some also as input/output parameters that both send in data and are updated to receive it.

Parameter-Liste

param

Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.

var

Name of the PHP variable to bind to the SQL statement parameter.

type

Explicit data type for the parameter using the PDO::PARAM_* constants. To return an INOUT parameter from a stored procedure, use the bitwise OR operator to set the PDO::PARAM_INPUT_OUTPUT bits for the type parameter.

maxLength

Length of the data type. To indicate that a parameter is an OUT parameter from a stored procedure, you must explicitly set the length. Meaningful only when type parameter is PDO::PARAM_INPUT_OUTPUT.

driverOptions

Rückgabewerte

Gibt bei Erfolg true zurück. Bei einem Fehler wird false zurückgegeben.

Beispiele

Beispiel #1 Execute a prepared statement with named placeholders

<?php
/* Execute a prepared statement by binding PHP variables */
$calories 150;
$colour 'red';
$sth $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < :calories AND colour = :colour'
);
$sth->bindParam('calories'$caloriesPDO::PARAM_INT);
/* Names can be prefixed with colons ":" too (optional) */
$sth->bindParam(':colour'$colourPDO::PARAM_STR);
$sth->execute();
?>

Beispiel #2 Execute a prepared statement with question mark placeholders

<?php
/* Execute a prepared statement by binding PHP variables */
$calories 150;
$colour 'red';
$sth $dbh->prepare('SELECT name, colour, calories
    FROM fruit
    WHERE calories < ? AND colour = ?'
);
$sth->bindParam(1$caloriesPDO::PARAM_INT);
$sth->bindParam(2$colourPDO::PARAM_STR);
$sth->execute();
?>

Beispiel #3 Call a stored procedure with an INOUT parameter

<?php
/* Call a stored procedure with an INOUT parameter */
$colour 'red';
$sth $dbh->prepare('CALL puree_fruit(?)');
$sth->bindParam(1$colourPDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT12);
$sth->execute();
print(
"After pureeing fruit, the colour is: $colour");
?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Definition von Stored Procedures - eine Einführung

Stored Procedures sind vordefinierte SQL-Codeblöcke, die in einer Datenbank gespeichert sind und bei Bedarf aufgerufen werden können. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Kategorie: mySQL-Tutorials

Wie kann man komplexe Abfragen mit SQL-Querys In MySQLi effektiv durchführen?

In diesem MySQL-Tutorial wird erklärt, wie komplexe SQL-Abfragen in MySQLi effizient durchgeführt werden können. Wir werden uns mit verschiedenen Aspekten der Datenbankabfrage beschäftigen und spezifische Methoden kennenlernen. ...

TheMax

Autor : TheMax
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

[Wichtig] Anmeldung im Forum

Guess the hidden word using logic and deduction in the engaging game of Wordle. Wordle nyt (https://wordlenytimes.net/) ​

Geschrieben von lenytimes am 19.04.2024 19:21:45
Forum: Fragen/Vorschläge zum Forum
Professioneller Webentwickler & Webdesigner

Of course, here is the translation: Hello, Thank you for your interest in the long-term project. Your extensive skills and experience in web dev ...

Geschrieben von Athelstan am 15.04.2024 09:25:39
Forum: Jobgesuche
Wir stellen unsere SEO-Agentur vor

Hallo In der heutigen digitalen Welt war es für Unternehmen noch nie so einfach, ihre Reichweite weltweit zu vergrößern. Wenn Sie außerhalb I ...

Geschrieben von thomasmuller am 14.04.2024 07:18:33
Forum: User stellen sich vor
Spielplan für 4 Gruppen zu je 6 Teams auf 2 Feldern

Hallöchen zusammen, ich versuche derzeit unseren Excel-Spielplan in PHP zu überführen. Eigentlich bin ich auch shon fertig - wenn da nicht dies ...

Geschrieben von derH0st am 11.04.2024 15:58:37
Forum: PHP Developer Forum