prepare.php 501 B

12345678910111213
  1. <?php
  2. try {
  3. $dbh = new PDO('mysql:host=localhost;dbname=test2', "test2", "TeSt2");
  4. $sth = $dbh->prepare('INSERT INTO person SET name = :name, surname = :surname, father_name = :father_name');
  5. $sth->execute(array( ":name" => "Donald", ":surname" => "Trump", ":father_name" => "Moishovich"));
  6. foreach($dbh->query("SELECT * FROM person") as $row) {
  7. print_r($row);
  8. }
  9. $dbh = null;
  10. } catch (PDOException $e) {
  11. print "Error!: " . $e->getMessage() . "<br/>";
  12. die();
  13. }