PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/export_log.php

https://bitbucket.org/nad2000/mysql-to-google-apps-spreadsheets-data-loader-refresh
PHP | 34 lines | 21 code | 3 blank | 10 comment | 3 complexity | ff6eb3134f76978e9d7afd46d0a796c3 MD5 | raw file
 1#!/usr/bin/php -f 
 2<?php
 3/**
 4 * Log table data export into CSV file
 5 *
 6 * @author Rad Cirskis (nad2000@gmail.com)
 7 */
 8require_once 'DataSource.php';
 9
10/**
11 * Log table data export into CSV file
12 * @param string $fileName
13 */
14function exportLog( $fileName ) {
15
16	$result = DataSource::getLogStmt();
17	$row = $result->fetch(PDO::FETCH_ASSOC) ;
18	if ( $row )
19	{
20		$logId = $row['LogId'];
21		$csv = fopen( $fileName, 'w');
22		fputcsv ( $csv , array_keys( $row ) );
23		while ( $row )
24		{
25			fputcsv ( $csv , $row);
26			if (isset($row[0])) $logId = $row[0];
27			$row = $result->fetch(PDO::FETCH_NUM);
28		}
29		fclose($csv);
30		DataSource::storeLastLogId($logId);
31	}
32}
33
34exportLog('log.csv');