Advertisement
michaelyuen

Untitled

Apr 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors',1); // enable php error display for easy trouble shooting
  3. error_reporting(E_ALL); // set error display to all
  4.  
  5. $db = new PDO("mysql:host=localhost;dbname=test", 'root', '');
  6.  
  7. $price = '8000';
  8. $permalink = 'something-good';
  9. $id = 1;
  10.  
  11. // works not with the following set to 0. You can comment this line as 1 is default
  12. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
  13.  
  14. $sql = "
  15. UPDATE test SET `permalink` = :permalink WHERE `id` = :id;
  16. UPDATE test2 SET `price` = :price WHERE `id` =:id;
  17. ";
  18.  
  19. try {
  20.     $stmt = $db->prepare($sql);
  21.         $stmt->bindParam(':permalink', $permalink, PDO::PARAM_STR);
  22.         $stmt->bindParam(':price', $price, PDO::PARAM_INT);
  23.         $stmt->bindParam(':id', $id, PDO::PARAM_INT);
  24.     $stmt->execute();
  25.         echo 'good';
  26. } catch (PDOException $e) {
  27.     echo $e->getMessage();
  28.     die();
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement