How can I pass a parameter value from PHP to jasper report query? -
i want pass student number '2014000030'
parameter value report student. how do using sql query below code. below code how have done it, not working, did go wrong?
php code
<?php //import phpjasperlibrary include_once('phpjasperlibrary/tcpdf/tcpdf.php'); include_once("phpjasperlibrary/phpjasperxml.inc.php"); //database connection details $server="localhost"; $db="student_portal"; $user="root"; $pass=""; $version="0.8b"; $pgport=5432; $pchartfolder="./class/pchart2"; $value = '2014000030'; //display errors should off in php.ini file ini_set('display_errors', 0); //setting path created jrxml file $xml = simplexml_load_file("test.jrxml"); $phpjasperxml = new phpjasperxml(); //$phpjasperxml->debugsql=true; $phpjasperxml->arrayparameter=array("parameter1"=>$value); $phpjasperxml->xml_dismantle($xml); $phpjasperxml->transferdbtoarray($server,$user,$pass,$db); $phpjasperxml->outpage("i"); //page output method i:standard output d:download file ?>
sql query
select i.stid,i.surname,i.first_name,i.other_names,i.dob,i.course,b.branch_name,r.exam_no,r.modules,m.module_name,r.result,rr.remark modules m,info i,results r,branches b,result_remarks rr r.modules=m.module_code , i.campus_code=b.branch_code , i.stid=r.stid , rr.result=r.remark
in command
$phpjasperxml->arrayparameter=array("parameter1"=>$value);
you passing value jasperreport parameter parameter name "parameter1"
define parameter inside of jrxml
(use class corresponding database)
<parameter name="parameter1" class="java.lang.string"/>
then use in query (i.stid=$p{parameter1}
).
select i.stid,i.surname,i.first_name,i.other_names,i.dob,i.course,b.branch_name,r.exam_no,r.modules,m.module_name,r.result,rr.remark modules m,info i,results r,branches b,result_remarks rr i.stid=$p{parameter1} , r.modules=m.module_code , i.campus_code=b.branch_code , i.stid=r.stid , rr.result=r.remark
its important set correct class (same database column) of $p{parameter1}
, pass same class parameter, since jasper report use prepared statement when query executed.
note: can use query expression i.stid='$p!{parameter1}'
, jasper report string substitution, not recommend since code allow sql injection.
Comments
Post a Comment