Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2. //Getting the requested Code
  3. $Code = $_GET['Code'];
  4.  
  5. //Importing database
  6. require_once('dbConnect.php');
  7.  
  8. //Creating sql query with where clause to get an specific employee
  9. $sql = "SELECT * FROM Usuario WHERE Code='$Code' ";
  10.  
  11. //getting result
  12. $r = mysqli_query($con,$sql);
  13.  
  14. //pushing result to an array
  15. $result = array();
  16. $row = mysqli_fetch_array($r);
  17. array_push($result,array(
  18. "Code"=>$row['Code'],
  19. "user"=>$row['user'],
  20. "Pass"=>$row['Pass'],
  21. "TipoUsuario"=>$row['TipoUsuario']
  22. ));
  23.  
  24. //displaying in json format
  25. echo json_encode(array('result'=>$result));
  26.  
  27. mysqli_close($con);
  28. ?>
  29.  
  30. <?php
  31. try{
  32. $dsn = "mysql:host=fdb3.runhosting.com;dbname=698193_admin";
  33. $username = "698193_admin";
  34. $password = "1234admin";
  35.  
  36. $pdo = new PDO($dsn, $username, $password);
  37. }
  38. catch(PDOException $e)
  39. {
  40. echo "No se pudo conectar a la base de datos".$e- >getMessage();
  41. }
  42.  
  43. try{
  44. $resultado = $pdo->prepare("SELECT Code,user,Pass,TipoUsuario FROM Usuarios WHERE Code = :Code ");
  45. $resultado->execute('Code'=>$Code);
  46. $registro=$resultado->fetchAll(PDO::FETCH_ASSOC);
  47. $json=json_encode($registro);
  48. return $json;
  49. }
  50. catch(PDOException $e){
  51. echo "No existe un registro con dicho código";
  52. }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement