Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <?php
  2. session_start();
  3. header('Content-Type: text/csv');
  4. header('Content-Disposition: attachment; filename='. 'file.csv');
  5. header('Pragma: no-cache');
  6. header("Expires: 0");
  7.  
  8. $serverName = "localhostSQLEXPRESS";
  9. $connectionInfo = array( "Database"=>"AuServer", "ReturnDatesAsStrings"=>"true");
  10. $conn = sqlsrv_connect( $serverName, $connectionInfo);
  11.  
  12. $sql = "select top 100 AuEvent.time_stamp, AusDatabase.Title, AuEvent.user_name, AuEvent.rec_id, LogEventDescription.description
  13. FROM AuEvent
  14. INNER JOIN LogEventDescription
  15. ON AuEvent.event_id=LogEventDescription.event_id
  16. INNER JOIN AusDatabase
  17. ON AuEvent.db_id=AusDatabase.ID
  18. WHERE LogEventDescription.lcid='1033'
  19. ORDER BY time_stamp DESC";
  20.  
  21. $stmt = sqlsrv_query( $conn, $sql );
  22. if( $stmt === false) {
  23. die( print_r( sqlsrv_errors(), true) );
  24. }
  25.  
  26. //sort results into an array for the table
  27. while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){
  28. echo "
  29. <tr>
  30. <td>". $row['time_stamp'] . "</td>
  31. <td><a href="dbfilter.php?id=". $row['Title'] . "">". $row['Title'] . "</a></td>
  32. <td><a href="userfilter.php?id=". $row['user_name'] . "">". $row['user_name'] . "</a></td>
  33. <td><a href="eventfilter.php?id=". $row['description'] . "">". $row['description'] . "</a></td>
  34. <td>". $row['rec_id'] . "</td>
  35. </tr>";
  36.  
  37.  
  38.  
  39. $fp = fopen('file.csv', 'w');
  40.  
  41. foreach ($row as $fields) {
  42. fputcsv($fp, $row);
  43. }
  44.  
  45. }
  46. ?>
  47.  
  48. <?php
  49.  
  50. session_start();
  51. $serverName = "localhostSQLEXPRESS";
  52. $connectionInfo = array("Database" => "AuServer", "ReturnDatesAsStrings" => "true");
  53. $conn = sqlsrv_connect($serverName, $connectionInfo);
  54.  
  55. $sql = "select top 100 AuEvent.time_stamp, AusDatabase.Title, AuEvent.user_name, AuEvent.rec_id, LogEventDescription.description
  56. FROM AuEvent
  57. INNER JOIN LogEventDescription
  58. ON AuEvent.event_id=LogEventDescription.event_id
  59. INNER JOIN AusDatabase
  60. ON AuEvent.db_id=AusDatabase.ID
  61. WHERE LogEventDescription.lcid='1033'
  62. ORDER BY time_stamp DESC";
  63.  
  64. $stmt = sqlsrv_query($conn, $sql);
  65. if ($stmt === false) {
  66. die(print_r(sqlsrv_errors(), true));
  67. }
  68.  
  69. $fp = fopen('file.csv', 'w');
  70. while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
  71. foreach ($row as $fields) {
  72. fputcsv($fp, $row);
  73. }
  74. }
  75.  
  76. $path = path/to/file;
  77. header('Content-Type: text/csv');
  78. header('Content-Disposition: attachment; filename="'.basename($file).'"');
  79. header('Content-Length: '.filesize($file));
  80. readfile($file);
  81.  
  82. ?>
  83.  
  84. <?php
  85.  
  86. session_start();
  87. $serverName = "localhostSQLEXPRESS";
  88. $connectionInfo = array("Database" => "AuServer", "ReturnDatesAsStrings" => "true");
  89. $conn = sqlsrv_connect($serverName, $connectionInfo);
  90.  
  91. $sql = "select top 100 AuEvent.time_stamp, AusDatabase.Title, AuEvent.user_name, AuEvent.rec_id, LogEventDescription.description
  92. FROM AuEvent
  93. INNER JOIN LogEventDescription
  94. ON AuEvent.event_id=LogEventDescription.event_id
  95. INNER JOIN AusDatabase
  96. ON AuEvent.db_id=AusDatabase.ID
  97. WHERE LogEventDescription.lcid='1033'
  98. ORDER BY time_stamp DESC";
  99.  
  100. $stmt = sqlsrv_query($conn, $sql);
  101. if ($stmt === false) {
  102. die(print_r(sqlsrv_errors(), true));
  103. }
  104.  
  105. $fp = fopen('file.csv', 'w');
  106. while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
  107. foreach ($row as $fields) {
  108. fputcsv($fp, $row);
  109. }
  110. }
  111.  
  112. $path = path/to/file;
  113. header('Content-Type: text/csv');
  114. header('Content-Disposition: attachment; filename="'.basename($file).'"');
  115. header('Content-Length: '.filesize($file));
  116. readfile($file);
  117.  
  118. ob_end_clean();
  119. ob_start();
  120.  
  121. while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
  122. echo "echo all data here, tr and td etc";
  123. }
  124. ob_flush();
  125. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement