Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <?php
  2. print_r($_POST);
  3. try {
  4. $dbh = new PDO("mysql:dbname=mydb;host=myhost", "myuser", "mypass" );
  5.  
  6. $value = $_POST['myLname'];
  7.  
  8. print $value ;
  9. //print $dbh ;
  10.  
  11. $stmt = $dbh->prepare("CALL check_user_exists(?)");
  12. $stmt->bindParam(1, $value, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 50);
  13.  
  14. // call the stored procedure
  15. $stmt->execute();
  16.  
  17. print "procedure returned $valuen";
  18.  
  19. echo "PDO connection object created";
  20. $dbh = null;
  21.  
  22. } catch(PDOException $e) {
  23. echo $e->getMessage();
  24. }
  25. ?>
  26.  
  27. <?php
  28.  
  29. $dbhost='myhost';
  30. $dbuser='mydb';
  31. $dbpassword='mypass';
  32. $db='mydb';
  33.  
  34. $con=mysql_connect($dbhost, $dbuser, $dbpassword) or die("Could not connect: " . mysql_error()); ;
  35. mysql_select_db($db,$con);
  36. $qry_str = "select check_user_exists('chadhass@hotmail.com')";
  37.  
  38. $rset = mysql_query($qry_str) or exit(mysql_error());
  39. $row = mysql_fetch_assoc($rset);
  40. mysql_close($con);
  41. foreach($row as $k=>$v)
  42. {
  43. print $k.'=>'.$v;
  44. }
  45.  
  46. ?>
  47.  
  48. CREATE
  49. FUNCTION `check_user_exists`(in_email
  50. VARCHAR(100)) RETURNS varchar(1) CHARSET utf8
  51. READS SQL DATA
  52. BEGIN
  53. DECLARE vcount INT;
  54. DECLARE vcount1 INT;
  55. SELECT COUNT(*) INTO vcount FROM USERS
  56. WHERE USEREMAIL=in_email;
  57. IF vcount=1 then
  58. SELECT COUNT(*) INTO vcount1 FROM USERS
  59. WHERE USEREMAIL=in_email and isactive=1;
  60. if vcount1=1 then
  61. return('1');
  62. else
  63. return('0');
  64. end if;
  65. ELSE
  66. RETURN('2');
  67. END IF;
  68. END
  69.  
  70. <?php
  71. //print_r($_POST);
  72. try {
  73. $dbh = new PDO(PDO("mysql:dbname=mydb;host=myhost", "myuser", "mypass" );
  74.  
  75.  
  76.  
  77. $value = $_POST['myLname'];
  78.  
  79.  
  80. $result = $dbh->prepare("select check_user_exists(?) as retval");
  81. $result->bindParam(1, $value, PDO::PARAM_STR, 2);
  82. $result->setFetchMode(PDO::FETCH_CLASS, 'stdClass');
  83. $result->execute();
  84. $obj = $result->fetch();
  85.  
  86. print($obj->retval);
  87.  
  88.  
  89.  
  90.  
  91. echo "PDO connection object created";
  92. $dbh = null;
  93. }
  94. catch(PDOException $e)
  95. {
  96. echo $e->getMessage();
  97. }
  98.  
  99. ?>
  100.  
  101. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement