jasperphp error passing parameters

2019-05-31 18:22发布

In a jasper report I have a sql sentence like this:

SELECT * FROM table $P!{my_where}

In my php program, I'm calling the report this way:

    JasperPHP::process(
        base_path() . '/app/reports/report.jasper', 
        false,
        array("pdf"),
        array("my_where" => "WHERE field = value"),
        \Config::get('database.connections.mysql')
        )->execute();

Then, this is the error message:

Wrong report param format!

Doing it the simple way works, I mean:

In the report:

SELECT * FROM table WHERE $P!{field} = $P{value}

In PHP:

    JasperPHP::process(
        base_path() . '/app/reports/report.jasper', 
        false,
        array("pdf"),
        array("field" => $my_field, "value" => $my_value),
        \Config::get('database.connections.mysql')
        )->execute();

The thing is, I need to build a where clause dynamically from several fields, so, passing a only "where" parameter is a must.

Any idea?

1条回答
贪生不怕死
2楼-- · 2019-05-31 19:09

Solved: is just necessary to double quote the parameter:

$my_where = '"' .  $my_where . '"';

JasperPHP::process(
    base_path() . '/app/reports/report.jasper', 
    false,
    array("pdf"),
    array("my_where" => $my_where),
    \Config::get('database.connections.mysql')
    )->execute();
查看更多
登录 后发表回答