Code has been added to clipboard!
Multiple MySQL Rows for PDO Users
Example
<?php
$server = 'server';
$user = 'user';
$pass = 'pass';
$db = 'db';
try {Â Â Â
$con = new PDO("mysql:host=$server;db=$db", $user, $pass);
// PDO error mode is set to exception
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// the transaction begins
$con->beginTransaction();
// our SQL statements
$con->exec("INSERT INTO users (name, surname, e_mail) VALUES ('Ben', 'Jefferson', '[email protected]')");
$con->exec("INSERT INTO users (name, surname, e_mail) VALUES ('Johnny', 'Eriksen', '[email protected]')");
$con->exec("INSERT INTO users (name, surname, e_mail) VALUES ('Mary', 'Julie', '[email protected]')");
// commit the transaction
$con->commit();
echo "Created new records.";Â Â Â
} catch(PDOException $err) {
// roll the transaction back if something fails
$con->rollback();
echo "Error message: " . $err->getMessage();
}
$con = null;
?>