Guest User

Mysql Stored Procedure Error (PDO version)

a guest
Apr 11th, 2018
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. echo "<h1>Running test_procedure_1</h2>";
  3. echo "<pre>";
  4. echo "CREATE PROCEDURE `test_procedure_1`()".
  5. "BEGIN".
  6. "   select 'gary';".
  7. "   CALL raise_error;".
  8. "END";
  9. echo "</pre>";
  10. //connect to database
  11. $connection = new \PDO("mysql:host=".$db['server'].";dbname=".$db['name'].";charset=utf8", $db['user'], $db['password']);
  12.  
  13.  
  14. $stmt = $connection->prepare("CALL test_procedure_1");
  15. if (!($stmt->execute())) {
  16.     echo "CALL failed: (" . $stmt->errorCode() . ") " . print_r($stmt->errorInfo(),true);
  17. }
  18. else{
  19.     //loop the result set
  20.     echo "RESULTS:";
  21.     while ($row = $stmt->fetch()) {
  22.         print_r($row);
  23.     }
  24. }
  25.  
  26.  
  27. echo "<br>----------<br>";
  28. echo "<h1>Running test_procedure_2</h2>";
  29. echo "<pre>";
  30. echo "CREATE PROCEDURE `test_procedure_2`()".
  31. "BEGIN".
  32. "   CALL raise_error;".
  33. "   select 'gary';".
  34. "END";
  35. echo "</pre>";
  36. $connection = new \PDO("mysql:host=".$db['server'].";dbname=".$db['name'].";charset=utf8", $db['user'], $db['password']);
  37.  
  38. $stmt = $connection->prepare("CALL test_procedure_2");
  39. if (!($stmt->execute())) {
  40.     echo "CALL failed: (" . $stmt->errorCode() . ") " . print_r($stmt->errorInfo(),true);
  41. }
  42. else{
  43.     //loop the result set
  44.     echo "RESULTS:";
  45.     while ($row = $stmt->fetch()) {
  46.         print_r($row);
  47.     }
  48. }
  49. echo "<br>----------<br>";
RAW Paste Data