MySQL - Flexible Insert-Funktion
<?php
// Flexible Insert-Funktion
$pdo = new PDO('mysql:host=localhost;dbname=test;charset=UTF-8', '', '');
function insertData($pdo, $table, $values) {
$tableHead = array_keys($values);
$comma_separated = implode(",", $tableHead);
$colon_separated = implode(",:", $tableHead);
$statement = $pdo->prepare("INSERT INTO " . $table . " (" . $comma_separated . ") VALUES (:" . $colon_separated . ")");
$statement->execute($values);
}
$table = "members";
$values = array('email' => 'max.mustermann@example.com', 'firstname' => 'Max', 'lastname' => 'Mustermann');
$aktion = insertData($pdo,$table,$values);
?>
Bausteine Alle Anzeigen
Eine zufällige Auswahl von Codeschnipseln
aus den Bereichen
HTML, CSS,
PHP, JavaScript und
MySQL.
<s> Physische Auszeichnung
CSS - Ladeanimation ohne Bild-Grafik
PHP - Zufallsgenerator (Lottozahlen)