-
Notifications
You must be signed in to change notification settings - Fork 0
/
fac_database_class.php
61 lines (43 loc) · 1.64 KB
/
fac_database_class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class facDatabase {
private $pg_pdo;
private $docpath;
public function __construct() {
include './config.php';
$this->docpath = $docpath;
// initialize variables
// connect to wws/erp fpr invoice details
$this->pg_pdo = new PDO($wwsserver, $wwsuser, $wwspass, $options);
}
public function splitQuery($sql, $splitField, $parameter, $outputFilePrefix, $header, $createType = "a") {
$row_qry = $this->pg_pdo->prepare($sql);
foreach ($parameter as $key => $value) {
$row_qry->bindValue($key, $value);
}
$row_qry->execute() or die (print_r($row_qry->errorInfo()));
$switch = null;
$path = pathinfo($outputFilePrefix);
while ($row = $row_qry->fetch( PDO::FETCH_ASSOC )) {
if ( ($switch != $row[$splitField]) or (!isset($output)) ) {
if (isset($output) and (get_resource_type($output) === 'file')) { fclose($output); }
print "<a href='".$this->docpath.$path['filename'].'_'.$row[$splitField].'.'.$path['extension']."'>";
print $this->docpath.$path['filename'].'_'.$row[$splitField].'.'.$path['extension']."</a><br>";
$output = fopen($this->docpath.$path['filename'].'_'.$row[$splitField].'.'.$path['extension'], $createType);
if ($header == null) {
fputcsv($output, array_keys($row),";",'"');
} else {
fputcsv($output, $header,";",'"');
}
$switch = $row[$splitField];
}
foreach($row as $key => $value) {
if((is_numeric($value)) and (strpos($value,'.') !== false)){
$row[$key] = str_replace(".",",",round($value,3));
}
}
fputcsv($output, $row,";",'"');
}
fclose($output);
}
}
?>