jasperphp error passing parameters

南笙酒味 提交于 2019-12-08 07:33:16

问题


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:


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();


来源:https://stackoverflow.com/questions/29551309/jasperphp-error-passing-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!