Advertisement
Guest User

Untitled

a guest
Sep 20th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <?php
  2. function mySQLi_connection(){
  3. $hostName = "localhost";
  4. $userName = "admin";
  5. $password = "admin";
  6. $databaseName = "db_name";
  7. $mysqli = new mysqli($hostName, $userName, $password, $databaseName);
  8. if($mysqli->connect_errno > 0){
  9. die('Unable to connect to database [' . $db->connect_error . ']');
  10. }
  11.  
  12. return $mysqli;
  13. }
  14.  
  15.  
  16. function getEmpNamebyID($id){
  17. $empname = NULL;
  18. echo "Inside getEmpNamebyID() with id = $id";
  19. $mysqli = mySQLi_connection();
  20. $qry = "SELECT `empname` FROM `employee_details` WHERE `EMP_ID` =?";
  21. if ($stmt2 = $mysqli ->prepare($qry)) {
  22.  
  23.  
  24. if($stmt2 === false) {
  25. trigger_error('Wrong SQL: ' . $qry . ' Error: ' . $mysqli->errno . ' ' . $mysqli->error, E_USER_ERROR);
  26. }
  27. if (!$stmt2->bind_param("s", $id)) {
  28. echo "Binding parameters failed: (" . $stmt2->errno . ") " . $stmt2->error;
  29. }
  30.  
  31.  
  32. if (!$stmt2->execute()) {
  33. echo "Execute failed: (" . $stmt2->errno . ") " . $stmt2->error;
  34. }
  35.  
  36.  
  37. if (!$stmt2->bind_result($empname)) {
  38. echo "Binding output parameters failed: (" . $stmt2->errno . ") " . $stmt->error;
  39. }
  40. }
  41. echo $empname;
  42. return $empname;
  43. }
  44.  
  45. echo getEmpNamebyID(95);
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement