KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Error with int parameters on query #520

Closed Daniel Amamoo-Otchere opened this topic on on Nov 15, 2018 - 7 comments

Daniel Amamoo-Otchere commented on Nov 15, 2018

Hi, I have challenge with getting this query to execute. I followed your examples but not sure if there is any way to see what is coming out. Glad for some assistance in resolving it.

The query

class PaymentList extends KoolReport
{
use \koolreport\inputs\POSTBinding;
use \koolreport\export\Exportable;
	
  protected function defaultParamValues()
    {
        return array(
            "academic_year_id"=>array(),      "term_id"=>array(),		"payment_call_id"=>array(),			"community_id"=>array()
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
			"academic_year_id",	"term_id",		"payment_call_id",	"community_id",
        );
    }

    public function settings()
    {
        $config = include "../config.php";
        return array(
            "dataSources"=>array(
                "abc"=>$config["postdb"]
            ),
        );
    }   
	
    protected function setup()
    {
        $this->src('abc')
        ->query("SELECT
					application_code,
					applicant_name,
					place as community,
					ds1.list_source_value as good_behaviour,
					ds2.list_source_value as rc_submitted,
					ds3.acada_year,
					ds4.list_source_value as pay_call_type,
					date_payment_call,
					payment_amount,
					concat('P',lpad(payment_call_id::text,4,'0'))  as payment_code
				FROM  nak_applicant_payment a
					INNER JOIN  nak_applicant b on a.applicant_id=b.applicant_id
					".
					(($this->params["term_id"]!=array())?" AND a.term_id IN (:term_id)":"")
					."
					INNER JOIN community ds5 on ds5.community_id = b.applied_community_id
					".
					(($this->params["community_id"]!=array())?" AND ds5.community_id IN (:community_id)":"")
					." 
					INNER JOIN controller.mydatasourcelist ds1 on ds1.mydatasourcelist_id=a.exhibit_good_behaviour_id
					INNER JOIN controller.mydatasourcelist ds2 on ds2.mydatasourcelist_id=a.report_card_received_id
					INNER JOIN academic_year ds3 on ds3.academic_year_id=a.academic_year_id		
					".
					(($this->params["academic_year_id"]!=array())?" AND a.academic_year_id IN (:academic_year_id)":"").
					".					
					INNER JOIN controller.mydatasourcelist ds4 on ds4.mydatasourcelist_id=a.payment_call_type_id
					".		
					(($this->params["payment_call_id"]!=array())?" AND a.payment_call_id IN (:payment_call_id)":"")
				)
						
				->params(array(
					":academic_year_id"=>(int)$this->params["academic_year_id"],
					":term_id"=>(int)$this->params["term_id"],
					":payment_call_id"=>(int)$this->params["payment_call_id"],
					":community_id"=>(int)$this->params["community_id"],
				))
				
				->pipe($this->dataStore("result"));

      $this->src("abc")->query("
            SELECT
                community_id,place
            FROM
                community a inner join nak_operation_areas b on a.community_id=b.community_id
            ORDER BY place
        ")
        ->pipe($this->dataStore("dscommunity"));
	
      $this->src("abc")->query("
            SELECT
                academic_year_id, acada_year
            FROM
                academic_year
            ORDER BY acada_year
        ")
        ->pipe($this->dataStore("dsacada_year"));
      
		
		$this->src("abc")->query("
            SELECT
                mydatasourcelist_id,list_source_value
            FROM
                controller.mydatasourcelist
            ORDER BY list_source_value
        ")
        ->pipe($this->dataStore("dsterm"));
   

		 $this->src("abc")->query("
            SELECT
                payment_call_id,concat('P',lpad(payment_call_id::text,4,'0')) as pay_code
            FROM
                payment_call
			WHERE academic_year_id in (:academic_year_id )
			AND term_id in (:pterm_id)
			ORDER BY payment_call_id
        ")
		  ->params(array(
            ":academic_year_id"=>$this->params["academic_year_id"],
            ":term_id"=>$this->params["term_id"]
		     ))	
        ->pipe($this->dataStore("dspsyment_call"));

 } 
}
.

The error I get on the page are


Notice: Undefined index: term_id in ..\PaymentList.php on line 67
Notice: Undefined index: community_id in ..\PaymentList.php on line 71
Notice: Undefined index: academic_year_id in ..\PaymentList.php on line 77
Notice: Undefined index: payment_call_id in ..\PaymentList.php on line 81
Notice: Undefined index: academic_year_id in ..\PaymentList.php on line 85
Notice: Undefined index: term_id in ..\PaymentList.php on line 86
Notice: Undefined index: payment_call_id in ..\PaymentList.php on line 87
Notice: Undefined index: community_id in ..\PaymentList.php on line 88 

Notice: Undefined index: academic_year_id in ..\PaymentList.php on line 132
Notice: Undefined index: term_id in ..\PaymentList.php on line 133

Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :academic_year_id in ..\PdoDataSource.php on line 125
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :term_id in ..\PdoDataSource.php on line 125
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :payment_call_id in ..\PdoDataSource.php on line 125
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :community_id in ..\PdoDataSource.php on line 125

Fatal error: Uncaught exception 'Exception' with message 'Query Error >> [ERROR: missing FROM-clause entry for table "academic_year_id" LINE 19: ...ER JOIN academic_year ds3 on ds3.academic_year_id=a.academic... ^] >> SELECT application_code, applicant_name, place as community, ds1.list_source_value as good_behaviour, ds2.list_source_value as rc_submitted, ds3.acada_year, ds4.list_source_value as pay_call_type, date_payment_call, payment_amount, concat('P',lpad(payment_call_id::text,4,'0')) as payment_code FROM nak_applicant_payment a INNER JOIN nak_applicant b on a.applicant_id=b.applicant_id INNER JOIN community ds5 on ds5.community_id = b.applied_community_id INNER JOIN controller.mydatasourcelist ds1 on ds1.mydatasourcelist_id=a.exhibit_good_behaviour_id INNER JOIN controller.mydatasourcelist ds2 on ds2.mydatasourcelist_id=a.report_card_received_id in C:\xampp\htdocs\koolreport\datasources\PdoDataSource.php on line 202

*

Daniel Amamoo-Otchere commented on Nov 15, 2018

PDODataSource

KoolReport commented on Nov 15, 2018

Please remove the (int) in front of the $this->params["term_id"] and other as well. Also, you may need to do this:

$query_params = array();

if($this->params["term_id"]!=array())
{
    $query_params["term_id"] =$this->params["term_id"];
}

You need to do the same for other ids as well.

Later you set this

->query('... you above query..')
->params($query_params);
Daniel Amamoo-Otchere commented on Nov 16, 2018

Please advice, where do I define this?

$query_params = array();
if($this->params["term_id"]!=array())
{
    $query_params["term_id"] =$this->params["term_id"];
}

which of the classes do I define it in I get the error

__Notice: Undefined variable: query_params in C:\xampp\htdocs\paceware\reports\kreports\PaymentList.php on line 95__

KoolReport commented on Nov 16, 2018

On top inside setup() method

Daniel Amamoo-Otchere commented on Nov 16, 2018

Please advice if I am on the right path!

  protected function defaultParamValues()
    {
			return array(	
			"academic_year_id"=>array(),
	        "term_id"=>array(),
			"payment_call_id"=>array(),
			"community_id"=>array(),
			);
    }

    protected function bindParamsToInputs()
    {
		return array("academic_year_id",
	        "term_id",
			"payment_call_id",
			"community_id",
			);
    }

    public function settings()
    {
        $config = include "config.php";
        return array(
            "dataSources"=>array(
                "nakdef"=>$config["postdb"]
            ),
        );
    }   
	
    protected function setup()
    {
		
	$query_params = array();
		if($this->params["academic_year_id"]!=array())
		{
			$query_params["academic_year_id"] =$this->params["academic_year_id"];
		}
		if($this->params["term_id"]!=array())
		{
			$query_params["term_id"] =$this->params["term_id"];
		}
			if($this->params["payment_call_id"]!=array())
		{
			$query_params["payment_call_id"] =$this->params["payment_call_id"];
		}
			if($this->params["community_id"]!=array())
		{
			$query_params["community_id"] =$this->params["community_id"];
		} 

        $this->src('nakdef')
        ->query("SELECT
					application_code,
					applicant_name,
					place as community,
					ds1.list_source_value as good_behaviour,
					ds2.list_source_value as rc_submitted,
					ds3.acada_year,
					ds4.list_source_value as pay_call_type,
					date_payment_call,
					payment_amount,
					concat('P',lpad(payment_call_id::text,4,'0'))  as payment_code
				FROM  nak_applicant_payment a
					INNER JOIN  nak_applicant b on a.applicant_id=b.applicant_id
					INNER JOIN community ds5 on ds5.community_id = b.applied_community_id
					INNER JOIN controller.mydatasourcelist ds1 on ds1.mydatasourcelist_id=a.exhibit_good_behaviour_id
					INNER JOIN controller.mydatasourcelist ds2 on ds2.mydatasourcelist_id=a.report_card_received_id
					INNER JOIN academic_year ds3 on ds3.academic_year_id=a.academic_year_id						
					INNER JOIN controller.mydatasourcelist ds4 on ds4.mydatasourcelist_id=a.payment_call_type_id
					WHERE
					a.academic_year_id IN (:academic_year_id) AND
					a.academic_term_id IN (:term_id) AND
					a.payment_call_id IN (:payment_call_id) AND
					ds5.community_id IN (:community_id)
				"
				)
						
				->params($query_params)
				->pipe($this->dataStore("result"));

I get the error

Fatal error: Uncaught exception 'Exception' with message 'Query Error >> [ERROR: bind message supplies 0 parameters, but prepared statement "pdo_stmt_00000001" requires 4] >> SELECT application_code, applicant_name, place as community, ds1.list_source_value as good_behaviour, ds2.list_source_value as rc_submitted, ds3.acada_year, ds4.list_source_value as pay_call_type, date_payment_call, payment_amount, concat('P',lpad(payment_call_id::text,4,'0')) as payment_code FROM nak_applicant_payment a INNER JOIN nak_applicant b on a.applicant_id=b.applicant_id INNER JOIN community ds5 on ds5.community_id = b.applied_community_id INNER JOIN controller.mydatasourcelist ds1 on ds1.mydatasourcelist_id=a.exhibit_good_behaviour_id INNER JOIN controller.mydatasourcelist ds2 on ds2.mydatasourcelist_id=a.report_card_received_id INNER JOIN academic_year ds3 on ds3.academic_year_id=a.academic_year_id INNER JOIN controller.mydatasour in C:\xampp\htdocs\koolreport\datasources\PdoDataSource.php on line 202

KoolReport commented on Nov 16, 2018

Please add the code in your previous version:

(($this->params["term_id"]!=array())?" AND a.term_id IN (:term_id)":"")

Those code is correct.

The idea is that whenever there is term_id selected by user, then we add the condition to the query as well as we add the parameter to the query.

Daniel Amamoo-Otchere commented on Nov 16, 2018

Hello KoolReport Team, May I request a seesion on my machine to get it resolved. Looks like the back and forth is not helping out. It continues to give me an error. Once it is resolved one can then post the code here for future reference.

Kindly let me know when it suites so I connect

Thanks.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

Inputs