Advertisement
EmadS3

Untitled

Dec 10th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. $dsn = 'mysql:host=localhost;dbname=test2';
  3. $user = 'root';
  4. $pass = 'root1234';
  5. $options = array(PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES UTF8');
  6. try{
  7.     $odma = new PDO($dsn, $user, $pass, $options);
  8.     $odma->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  9.     echo "Successfully connected";
  10.     $query = "INSERT INTO `products` (`id`, `name`) VALUES (NULL, 'product4')";
  11.     $odma->exec($query);
  12.    
  13. }
  14. catch( PDOException $error)
  15. {
  16.     echo "failed" . $error->getMessage();
  17. }
  18. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement