<?php
$pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$statement = $pdo->prepare("INSERT INTO users (email, vorname, nachname) VALUES (?, ?, ?)");
$statement->execute(array('info@php-einfach.de', 'Klaus', 'Neumann'));
?>
//insertquery
$insertquery = "insert into pdo_table(name,age,class,gender) values('sadia',12,11,'female') ";
$dbcon->query($insertquery);
//$dbcon->exec($insertquery);
echo '<br>'.'inserted successful';
<?php
$pdo = require_once 'connect.php';
// insert a single publisher
$name = 'Macmillan';
$sql = 'INSERT INTO publishers(name) VALUES(:name)';
$statement = $pdo->prepare($sql);
$statement->execute([
':name' => $name
]);
$publisher_id = $pdo->lastInsertId();
echo 'The publisher id ' . $publisher_id . ' was inserted';
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email)
VALUES (:firstname, :lastname, :email)");
$stmt->bindParam(':firstname', $firstname);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':email', $email);
// insert a row
$firstname = "John";
$lastname = "Doe";
$email = "john@example.com";
$stmt->execute();
$stmt = $pdo->prepare("INSERT INTO table (column_name) VALUES (?)");
$stmt->execute([$value]);
$stmt = $conn->prepare("INSERT INTO MyGuests (firstname, lastname, email)
VALUES (:firstname, :lastname, :email)");
$stmt->bindParam(':firstname', $firstname);
$stmt->bindParam(':lastname', $lastname);
$stmt->bindParam(':email', $email);
// insert a row
$firstname = "John";
$lastname = "Doe";
$email = "john@example.com";
$stmt->execute();