Advertisement
NoHatred0

Untitled

Jul 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2.  
  3. include_once '../functions.php';
  4.  
  5. function getUserFromDB($targetUser, $targetPass)
  6. {
  7. $user = [
  8. 'id' => '',
  9. 'username' => '',
  10. 'password' => '',
  11. ];
  12.  
  13. $dbConfig = [
  14. 'hostname' => '127.0.0.1',
  15. 'user' => 'root',
  16. 'password' => '1234',
  17. 'database' => 'internshp',
  18. ];
  19.  
  20. $dbLink = mysqli_connect($dbConfig['hostname'],
  21. $dbConfig['user'],
  22. $dbConfig['password'],
  23. $dbConfig['database']);
  24.  
  25. $query = "SELECT *
  26. FROM user
  27. WHERE username LIKE '$targetUser'
  28. AND password LIKE '$targetPass'";
  29.  
  30. if($stmt = mysqli_prepare($dbLink, $query))
  31. {
  32. mysqli_stmt_execute($stmt);
  33. mysqli_stmt_bind_result($stmt, $user['id'], $user['username'], $user['password']);
  34.  
  35. echo '<pre>';
  36. while (mysqli_stmt_fetch($stmt))
  37. {
  38. //printf("%s\t%s\t%s\n", $user['id'], $user['username'], $user['password']);
  39. }
  40. echo '</pre>';
  41.  
  42. mysqli_stmt_close($stmt);
  43. }
  44.  
  45. mysqli_close($dbLink);
  46.  
  47. return $user;
  48. }
  49.  
  50. $result = getUserFromDB('gigi', 'coco');
  51. showMe_dump($result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement