Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- header('Content-Type: text/csv');
- header('Content-Disposition: attachment; filename='. 'file.csv');
- header('Pragma: no-cache');
- header("Expires: 0");
- $serverName = "localhostSQLEXPRESS";
- $connectionInfo = array( "Database"=>"AuServer", "ReturnDatesAsStrings"=>"true");
- $conn = sqlsrv_connect( $serverName, $connectionInfo);
- $sql = "select top 100 AuEvent.time_stamp, AusDatabase.Title, AuEvent.user_name, AuEvent.rec_id, LogEventDescription.description
- FROM AuEvent
- INNER JOIN LogEventDescription
- ON AuEvent.event_id=LogEventDescription.event_id
- INNER JOIN AusDatabase
- ON AuEvent.db_id=AusDatabase.ID
- WHERE LogEventDescription.lcid='1033'
- ORDER BY time_stamp DESC";
- $stmt = sqlsrv_query( $conn, $sql );
- if( $stmt === false) {
- die( print_r( sqlsrv_errors(), true) );
- }
- //sort results into an array for the table
- while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){
- echo "
- <tr>
- <td>". $row['time_stamp'] . "</td>
- <td><a href="dbfilter.php?id=". $row['Title'] . "">". $row['Title'] . "</a></td>
- <td><a href="userfilter.php?id=". $row['user_name'] . "">". $row['user_name'] . "</a></td>
- <td><a href="eventfilter.php?id=". $row['description'] . "">". $row['description'] . "</a></td>
- <td>". $row['rec_id'] . "</td>
- </tr>";
- $fp = fopen('file.csv', 'w');
- foreach ($row as $fields) {
- fputcsv($fp, $row);
- }
- }
- ?>
- <?php
- session_start();
- $serverName = "localhostSQLEXPRESS";
- $connectionInfo = array("Database" => "AuServer", "ReturnDatesAsStrings" => "true");
- $conn = sqlsrv_connect($serverName, $connectionInfo);
- $sql = "select top 100 AuEvent.time_stamp, AusDatabase.Title, AuEvent.user_name, AuEvent.rec_id, LogEventDescription.description
- FROM AuEvent
- INNER JOIN LogEventDescription
- ON AuEvent.event_id=LogEventDescription.event_id
- INNER JOIN AusDatabase
- ON AuEvent.db_id=AusDatabase.ID
- WHERE LogEventDescription.lcid='1033'
- ORDER BY time_stamp DESC";
- $stmt = sqlsrv_query($conn, $sql);
- if ($stmt === false) {
- die(print_r(sqlsrv_errors(), true));
- }
- $fp = fopen('file.csv', 'w');
- while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
- foreach ($row as $fields) {
- fputcsv($fp, $row);
- }
- }
- $path = path/to/file;
- header('Content-Type: text/csv');
- header('Content-Disposition: attachment; filename="'.basename($file).'"');
- header('Content-Length: '.filesize($file));
- readfile($file);
- ?>
- <?php
- session_start();
- $serverName = "localhostSQLEXPRESS";
- $connectionInfo = array("Database" => "AuServer", "ReturnDatesAsStrings" => "true");
- $conn = sqlsrv_connect($serverName, $connectionInfo);
- $sql = "select top 100 AuEvent.time_stamp, AusDatabase.Title, AuEvent.user_name, AuEvent.rec_id, LogEventDescription.description
- FROM AuEvent
- INNER JOIN LogEventDescription
- ON AuEvent.event_id=LogEventDescription.event_id
- INNER JOIN AusDatabase
- ON AuEvent.db_id=AusDatabase.ID
- WHERE LogEventDescription.lcid='1033'
- ORDER BY time_stamp DESC";
- $stmt = sqlsrv_query($conn, $sql);
- if ($stmt === false) {
- die(print_r(sqlsrv_errors(), true));
- }
- $fp = fopen('file.csv', 'w');
- while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
- foreach ($row as $fields) {
- fputcsv($fp, $row);
- }
- }
- $path = path/to/file;
- header('Content-Type: text/csv');
- header('Content-Disposition: attachment; filename="'.basename($file).'"');
- header('Content-Length: '.filesize($file));
- readfile($file);
- ob_end_clean();
- ob_start();
- while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
- echo "echo all data here, tr and td etc";
- }
- ob_flush();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement