Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php $stmt = $pdo->prepare("INSERT INTO products (name, price, stock) VALUES (:name, :price, :stock)"); // bindValue: bind the current value $stmt->bindValue(":name", $productName, PDO::PARAM_STR); $stmt->bindValue(":price", $price, PDO::PARAM_STR); // PDO has no PARAM_FLOAT $stmt->bindValue(":stock", $stock, PDO::PARAM_INT); $stmt->execute(); // bindParam: binds by reference (useful in loops) $stmt = $pdo->prepare("INSERT INTO tags (name) VALUES (:name)"); $stmt->bindParam(":name", $tagName, PDO::PARAM_STR); foreach ($tags as $tagName) { $stmt->execute(); // Uses current value of $tagName }
Result
Open