Skip to content

Commit eab60d7

Browse files
committed
env change, formatting
1 parent 0b6b0da commit eab60d7

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

example-mysql-53.php

+10-14
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
error_reporting(-1);
33
ini_set('display_errors', true);
44

5-
//settings - libarary-related
5+
//settings - library-related
66
$log = getenv('LOG') ?: '/tmp/php_error.log';
77
$logTemporaryDir = getenv('LOG_TEMPORARY_DIR') ?: '/tmp/php_error';
8-
$keepLogDir = getenv('KEEP_LOG_DIR') ?: '/tmp/php_error_keep';
8+
$logKeepDir = getenv('LOG_KEEP_DIR') ?: '/tmp/php_error_keep';
99

1010
//settings - custom-code related
1111
$host = getenv('MYSQL_HOST') ?: 'localhost';
@@ -14,15 +14,11 @@
1414
$password = getenv('MYSQL_PASSWORD') ?: '';
1515
$database = getenv('MYSQL_DATABASE') ?: 'test';
1616
$table = getenv('MYSQL_TABLE') ?: 'php_error';
17-
$extra = getenv('EXTRA_COLUMNS'); //for example host=host1,env=cli
18-
//assumes that host and env columns are presented in mysql table
19-
20-
//parse env
21-
$extraFields = array();
22-
if ($extra) {
23-
foreach(explode(',', $extra) as $tmp) {
17+
$extraColumns = array();
18+
if (getenv('EXTRA_COLUMNS')) {
19+
foreach(explode(',', getenv('EXTRA_COLUMNS')) as $tmp) {
2420
list ($k, $v) = explode('=', $tmp);
25-
$extraFields[trim($k)] = trim($v);
21+
$extraColumns[trim($k)] = trim($v);
2622
}
2723
}
2824

@@ -33,13 +29,13 @@
3329

3430
//prepare insert query
3531
$sqlColumns = array('datetime = :datetime', 'message = :message');
36-
foreach (array_keys($extraFields) as $column) {
32+
foreach (array_keys($extraColumns) as $column) {
3733
$sqlColumns[] = "{$column} = :{$column}";
3834
}
3935
$sql = "INSERT INTO {$table} SET " . join(', ', $sqlColumns);
4036
$sth = $dbh->prepare($sql);
41-
foreach (array_keys($extraFields) as $column) {
42-
$sth->bindParam(':' . $column, $extraFields[$column]);
37+
foreach (array_keys($extraColumns) as $column) {
38+
$sth->bindParam(':' . $column, $extraColumns[$column]);
4339
}
4440

4541
$datetime = $message = null;
@@ -58,5 +54,5 @@
5854

5955
//run
6056
require 'lib-53.php';
61-
$phpLogParser53 = new PhpLogParser53($log, $logTemporaryDir, $sendErrors, 2, $keepLogDir);
57+
$phpLogParser53 = new PhpLogParser53($log, $logTemporaryDir, $sendErrors, 2, $logKeepDir);
6258
$phpLogParser53->start();

0 commit comments

Comments
 (0)