Guest User

Untitled

a guest
Apr 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. $DB_host = "localhost";
  2. $DB_user = "root";
  3. $DB_pass = "";
  4. $DB_name = "";
  5.  
  6. try
  7. {
  8. $db_con = new PDO("mysql:host={$DB_host};dbname=
  9.  
  10. {$DB_name}",$DB_user,$DB_pass);
  11. $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  12. }
  13. catch(PDOException $e)
  14. {
  15. echo "ERROR : ".$e->getMessage();
  16. }
  17.  
  18.  
  19. $conn = new mysqli('localhost', 'root', '');
  20. mysqli_select_db($conn, 'EmployeeDB');
  21.  
  22. $setSql = "SELECT `ur_Id`,`ur_username`,`ur_password` FROM `tbl_user`";
  23. $setRec = mysqli_query($conn,$setSql);
  24.  
  25. $stmt=$db_con->prepare('select * from registros');
  26. $stmt->execute();
  27.  
  28.  
  29. $columnHeader ='';
  30. $columnHeader = "Sr NO"."t"."Book Name"."t"."Book Author"."t"."Book
  31. ISBN"."t";
  32.  
  33.  
  34. $setData='';
  35.  
  36. while($rec =$stmt->FETCH(PDO::FETCH_ASSOC))
  37. {
  38. $rowData = '';
  39. foreach($rec as $value)
  40. {
  41. $value = '"' . $value . '"' . "t";
  42. $rowData .= $value;
  43. }
  44. $setData .= trim($rowData)."n";
  45. }
  46.  
  47.  
  48. header("Content-type: application/octet-stream");
  49. header("Content-Disposition: attachment; filename=Book record sheet.xls");
  50. header("Pragma: no-cache");
  51. header("Expires: 0");
  52.  
  53. echo ucwords($columnHeader)."n".$setData."n";
  54.  
  55. ?>
Add Comment
Please, Sign In to add comment