From af7e4aef4f2ee177b5d8d4139558dc508887d019 Mon Sep 17 00:00:00 2001 From: mijzcx Date: Mon, 19 Aug 2013 11:48:13 +0800 Subject: [PATCH 1/3] connect using PDO and just array for fields --- class/PHPJasperXML.inc.php | 113 +++++++++++++++++++++++++++----- class/pchart2/cache/nothing.txt | 0 sample1a.php | 47 +++++++++++++ sample2a.php | 35 ++++++++++ setting.php | 2 +- 5 files changed, 179 insertions(+), 18 deletions(-) mode change 100644 => 100755 class/pchart2/cache/nothing.txt create mode 100644 sample1a.php create mode 100644 sample2a.php diff --git a/class/PHPJasperXML.inc.php b/class/PHPJasperXML.inc.php index dc70be7..4e6f13f 100755 --- a/class/PHPJasperXML.inc.php +++ b/class/PHPJasperXML.inc.php @@ -8,6 +8,8 @@ class PHPJasperXML { private $lang; private $previousarraydata; public $debugsql=false; + public $tempchartfolder; + public $pchartfolder; private $myconn; private $con; public $group_name; @@ -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; @@ -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; @@ -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"]; @@ -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) @@ -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; @@ -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."

"; $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; @@ -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; @@ -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."

"; $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; @@ -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; @@ -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."

"; $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; diff --git a/class/pchart2/cache/nothing.txt b/class/pchart2/cache/nothing.txt old mode 100644 new mode 100755 diff --git a/sample1a.php b/sample1a.php new file mode 100644 index 0000000..7e286d5 --- /dev/null +++ b/sample1a.php @@ -0,0 +1,47 @@ +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 + + +?> diff --git a/sample2a.php b/sample2a.php new file mode 100644 index 0000000..b17343c --- /dev/null +++ b/sample2a.php @@ -0,0 +1,35 @@ +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 + + +?> diff --git a/setting.php b/setting.php index 63b60bd..7164f7c 100644 --- a/setting.php +++ b/setting.php @@ -2,7 +2,7 @@ $server="localhost"; $db="phpjasperxml"; $user="root"; -$pass="user1"; +$pass="password"; $version="0.8d"; $pgport=5432; $pchartfolder="./class/pchart2"; From 9b4a328cd852d3fee102dafd7e33453c8ef8b2c9 Mon Sep 17 00:00:00 2001 From: mijzcx Date: Mon, 19 Aug 2013 12:05:30 +0800 Subject: [PATCH 2/3] update pass --- setting.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setting.php b/setting.php index 7164f7c..a592210 100644 --- a/setting.php +++ b/setting.php @@ -2,8 +2,8 @@ $server="localhost"; $db="phpjasperxml"; $user="root"; -$pass="password"; +$pass="user1"; $version="0.8d"; $pgport=5432; -$pchartfolder="./class/pchart2"; +// $pchartfolder="./class/pchart2"; ?> From 438c969b65f7cf04ced85bcbff8e36bb5d0776b8 Mon Sep 17 00:00:00 2001 From: mijzcx Date: Mon, 19 Aug 2013 12:06:07 +0800 Subject: [PATCH 3/3] update pchartfolder setting --- setting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setting.php b/setting.php index a592210..63b60bd 100644 --- a/setting.php +++ b/setting.php @@ -5,5 +5,5 @@ $pass="user1"; $version="0.8d"; $pgport=5432; -// $pchartfolder="./class/pchart2"; +$pchartfolder="./class/pchart2"; ?>