Search code examples
phplaraveljasper-reportslaravel-5.5

Laravel 5.5 Cossou iReport always return null


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. :-(


Solution

  • 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