Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect using PDO and plain array fields #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 96 additions & 17 deletions class/PHPJasperXML.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class PHPJasperXML {
private $lang;
private $previousarraydata;
public $debugsql=false;
public $tempchartfolder;
public $pchartfolder;
private $myconn;
private $con;
public $group_name;
Expand All @@ -22,6 +24,7 @@ class PHPJasperXML {
private $detailallowtill=0;
private $report_count=1; //### New declaration (variable exists in original too)
private $group_count = array(); //### New declaration

public function PHPJasperXML($lang="en",$pdflib="TCPDF") {
$this->lang=$lang;

Expand Down Expand Up @@ -946,6 +949,26 @@ public function element_subReport($data) {
"subreportExpression"=>$subreportExpression,"hidden_type"=>"subreport");
}

public function transferFieldtoArray($array_fields) {

$this->arraysqltable = $array_fields;
$this->m = count($this->arraysqltable) - 1;
}

public function transferPDOtoArray($conn) {

error_log("hello");
if ($this->debugsql == true) {
echo $this->sql;
die;
}

$stmt = $conn->prepare($this->sql);
$stmt->execute();
$this->arraysqltable = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->m = count($this->arraysqltable) - 1;
}

public function transferDBtoArray($host,$user,$password,$db_or_dsn_name,$cndriver="mysql") {
$this->m=0;

Expand Down Expand Up @@ -984,7 +1007,7 @@ public function transferDBtoArray($host,$user,$password,$db_or_dsn_name,$cndrive
else {
@mysql_query("set names 'utf8'");
$result = @mysql_query($this->sql); //query from db

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach($this->arrayfield as $out) {
$this->arraysqltable[$this->m]["$out"]=$row["$out"];
Expand Down Expand Up @@ -1326,7 +1349,10 @@ public function outpage($out_method="I",$filename="") {
if($filename=="")
$filename=$this->arrayPageSetting["name"].".pdf";

$this->disconnect($this->cndriver);
if ($this->cndriver != null) {
$this->disconnect($this->cndriver);
}
// $this->disconnect($this->cndriver);
$this->pdf->SetXY(10,10);
//$this->pdf->IncludeJS($this->createJS());
//($name, $w, $h, $caption, $action, $prop=array(), $opt=array(), $x='', $y='', $js=false)
Expand Down Expand Up @@ -1505,18 +1531,34 @@ public function setChartColor(){
public function showLineChart($data,$y_axis){
global $tmpchartfolder,$pchartfolder;

if( isset($this->pchartfolder) )
$pchartfolder= $this->pchartfolder;

if($pchartfolder == NULL || $pchartfolder == "")
$pchartfolder= "./pchart2";

if($pchartfolder=="")
$pchartfolder="./pchart2";
if (!is_dir($pchartfolder)) {
error_log($pchartfolder . " does not exists");
return;
}

//echo "$pchartfolder/class/pData.class.php";die;

include_once("$pchartfolder/class/pData.class.php");
include_once("$pchartfolder/class/pDraw.class.php");
include_once("$pchartfolder/class/pImage.class.php");

if( isset($this->tmpchartfolder) )
$tmpchartfolder= $this->tmpchartfolder;

if($tmpchartfolder=="")
$tmpchartfolder=$pchartfolder."/cache";

if (!is_dir($tmpchartfolder)) {
error_log($tmpchartfolder . " does not exists");
return;
}

$w=$data['width']+0;
$h=$data['height']+0;

Expand Down Expand Up @@ -1574,13 +1616,14 @@ public function showLineChart($data,$y_axis){
else
$sql=$this->sql;

$result = @mysql_query($sql); //query from db
// $result = @mysql_query($sql); //query from db
$result = $this->arraysqltable;
$chartdata=array();
$i=0;
//echo $sql."<br/><br/>";
$seriesname=array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

// while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($result as $row) {
$j=0;
foreach($row as $key => $value){
//$chartdata[$j][$i]=$value;
Expand Down Expand Up @@ -1816,17 +1859,34 @@ public function showBarChart($data,$y_axis,$type='barChart'){
global $tmpchartfolder,$pchartfolder;


if($pchartfolder=="")
$pchartfolder="./pchart2";
if( isset($this->pchartfolder) )
$pchartfolder= $this->pchartfolder;

if($pchartfolder == NULL || $pchartfolder == "")
$pchartfolder= "./pchart2";

if (!is_dir($pchartfolder)) {
error_log($pchartfolder . " does not exists");
return;
}

//echo "$pchartfolder/class/pData.class.php";die;

include_once("$pchartfolder/class/pData.class.php");
include_once("$pchartfolder/class/pDraw.class.php");
include_once("$pchartfolder/class/pImage.class.php");

if( isset($this->tmpchartfolder) )
$tmpchartfolder= $this->tmpchartfolder;

if($tmpchartfolder=="")
$tmpchartfolder=$pchartfolder."/cache";

if (!is_dir($tmpchartfolder)) {
error_log($tmpchartfolder . " does not exists");
return;
}

$w=$data['width']+0;
$h=$data['height']+0;

Expand Down Expand Up @@ -1883,13 +1943,14 @@ public function showBarChart($data,$y_axis,$type='barChart'){
else
$sql=$this->sql;

$result = @mysql_query($sql); //query from db
// $result = @mysql_query($sql); //query from db
$result = $this->arraysqltable;
$chartdata=array();
$i=0;
//echo $sql."<br/><br/>";
$seriesname=array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

// while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($result as $row) {
$j=0;
foreach($row as $key => $value){
//$chartdata[$j][$i]=$value;
Expand Down Expand Up @@ -2135,17 +2196,34 @@ public function showAreaChart($data,$y_axis,$type){
global $tmpchartfolder,$pchartfolder;


if($pchartfolder=="")
$pchartfolder="./pchart2";
if( isset($this->pchartfolder) )
$pchartfolder= $this->pchartfolder;

if($pchartfolder == NULL || $pchartfolder == "")
$pchartfolder= "./pchart2";

if (!is_dir($pchartfolder)) {
error_log($pchartfolder . " does not exists");
return;
}

//echo "$pchartfolder/class/pData.class.php";die;

include_once("$pchartfolder/class/pData.class.php");
include_once("$pchartfolder/class/pDraw.class.php");
include_once("$pchartfolder/class/pImage.class.php");

if( isset($this->tmpchartfolder) )
$tmpchartfolder= $this->tmpchartfolder;

if($tmpchartfolder=="")
$tmpchartfolder=$pchartfolder."/cache";

if (!is_dir($tmpchartfolder)) {
error_log($tmpchartfolder . " does not exists");
return;
}

$w=$data['width']+0;
$h=$data['height']+0;

Expand Down Expand Up @@ -2203,13 +2281,14 @@ public function showAreaChart($data,$y_axis,$type){
else
$sql=$this->sql;

$result = @mysql_query($sql); //query from db
// $result = @mysql_query($sql); //query from db
$result = $this->arraysqltable;
$chartdata=array();
$i=0;
//echo $sql."<br/><br/>";
$seriesname=array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

// while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($result as $row) {
$j=0;
foreach($row as $key => $value){
//$chartdata[$j][$i]=$value;
Expand Down
Empty file modified class/pchart2/cache/nothing.txt
100644 → 100755
Empty file.
47 changes: 47 additions & 0 deletions sample1a.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
include_once('class/tcpdf/tcpdf.php');
include_once("class/PHPJasperXML.inc.php");
// include_once ('setting.php'); now optional



$xml = simplexml_load_file("sample1.jrxml");


$PHPJasperXML = new PHPJasperXML();
//$PHPJasperXML->debugsql=true;
$PHPJasperXML->arrayParameter=array("parameter1"=>1);
$PHPJasperXML->xml_dismantle($xml);

$array_fields = array( array( "sample1_no"=>2,
"sample1_date"=>"2009-08-26",
"sample1_itemname"=>"???",
"sample1_qty"=>2,
"sample1_uom"=>"PCS"),
array( "sample1_no"=>3,
"sample1_date"=>"2009-08-15",
"sample1_itemname"=>"LCD Monitor",
"sample1_qty"=>1,
"sample1_uom"=>"PCS"),
array( "sample1_no"=>4,
"sample1_date"=>"2009-08-11",
"sample1_itemname"=>"test item 3",
"sample1_qty"=>3,
"sample1_uom"=>"pcs"),
array( "sample1_no"=>6,
"sample1_date"=>"2009-08-11",
"sample1_itemname"=>"Again, sample data",
"sample1_qty"=>8,
"sample1_uom"=>"day"));

$PHPJasperXML->transferFieldtoArray( $array_fields);

// $PHPJasperXML->transferDBtoArray($server,$user,$pass,$db); now optional
$PHPJasperXML->outpage("I"); //page output method I:standard output D:Download file


?>
35 changes: 35 additions & 0 deletions sample2a.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

include_once('class/tcpdf/tcpdf.php');
include_once("class/PHPJasperXML.inc.php");
include_once ('setting.php'); // set here

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);


$xml = simplexml_load_file("sample2.jrxml");

$PHPJasperXML = new PHPJasperXML();
//$PHPJasperXML->debugsql=true;
$PHPJasperXML->arrayParameter=array("parameter1"=>1);
$PHPJasperXML->pchartfolder="./class/pchart2"; // you can setup like this

$PHPJasperXML->xml_dismantle($xml);



$pdo = new PDO("mysql:host=$server;dbname=$db", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

// you can connect using PDO
$PHPJasperXML->transferPDOtoArray($pdo);

$PHPJasperXML->outpage("I"); //page output method I:standard output D:Download file


?>