1

I have managed to connect my app with ireport 5.6.0. It does produces a pdf file. My only problem now is that the pdf file only contains one row and null values.

Although I have tested it a lot, I even printed the parameter directly in the report and it is displayed. I don't know what to do anymore.

When I tried to query in iReport it gives me value like in the image enter image description here

But when I transfer the condition in my code, it will just give me a pdf file with null and one row.

$my_where = "where fempidno='0828' and year(fdate)='2017' and month(fdate)='08' limit 30";
        $text = '"' .  $my_where . '"';
        $output = public_path() . '/reports/report1';
        $jasper = new JasperPHP;
        // Compile a JRXML to Jasper
        $jasper->compile(public_path() . '/reports/report1.jrxml')->execute();

        $jasper->process(
            base_path('/public/reports/report1.jasper'),
            false,
            array('pdf'),
            array('title' => $text)
        )->execute();

I also replaced in iReport so that it will be

SELECT * FROM dtr $P!{title}

The result will is still null with one row only. :-(

Alex K
  • 22,315
  • 19
  • 108
  • 236
Ikong
  • 2,540
  • 4
  • 38
  • 58
  • Did you try to check `$P!{title}` with help of textField? – Alex K Jan 29 '18 at 07:36
  • yes, it actually display the query chunk from my app – Ikong Jan 29 '18 at 08:12
  • BTW, did you pass connection to the report? – Alex K Jan 29 '18 at 08:21
  • where fempidno='0828' and year(fdate)='2017' and month(fdate)='08' limit 30 --- that's the value in my variable it actually passed in to the report. Yes I tested the connection I used mysql.jdbc – Ikong Jan 29 '18 at 08:23
  • `Yes I tested the connection I used mysql.jdbc` - I don't see code for passing connection (like this: `Config::get('database.connections')`). You should look at [jasperphp error passing parameters](https://stackoverflow.com/q/29551309/876298) post – Alex K Jan 29 '18 at 08:35
  • Yeah you can post this as an answer. I actually tried that last time, and just realized that I have referenced to a wrong database that's why its not populating. thanks – Ikong Jan 29 '18 at 08:43

1 Answers1

1

Looks like you did not pass connection or used the wrong connection string.

You can pass connection like at this sample:

JasperPHP::process(
    base_path('/public/reports/report1.jasper'),
    false,
    array('pdf'),
    array('title' => $text),
    array(
      'driver' => 'postgres',
      'username' => 'username',
      'host' => 'localhost',
      'database' => 'mydb',
      'port' => '5433',
    )
  )->execute();

or like this:

JasperPHP::process(
    base_path('/public/reports/report1.jasper'), 
    false,
    array('pdf'),
    array('title' => $text),
    \Config::get('database.connections.mysql')
)->execute();

More information about using JasperPHP can be found here

Alex K
  • 22,315
  • 19
  • 108
  • 236