Advertisement
michaelyuen

Untitled

Apr 26th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 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. $column_name = 'something1';
  8. @column_name2 = 1234;
  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 `column_name` = :column_name WHERE `id` = :id;
  16. UPDATE test2 SET `column_name` = :column_name2 WHERE `id` =:id;
  17. ";
  18.  
  19. try {
  20.     $stmt = $db->prepare($sql);
  21.         $stmt->bindParam(':column_name', $column_name, PDO::PARAM_STR);
  22.         $stmt->bindParam(':column_name', $column_name2, PDO::PARAM_INT);
  23.         $stmt->bindParam(':id', $id, PDO::PARAM_INT);
  24.     $stmt->execute();
  25.         echo 'done';
  26. } catch (PDOException $e) {
  27.     echo $e->getMessage();
  28.     die();
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement