Jump to content

PDO::PARAM_INT Param Type gives error


KarlvonKarton
 Share

Recommended Posts

function getKappers($limit = 10){	
	$results_array = array();	
	$rs = wire('database')->prepare("SELECT * FROM appointment_kapper WHERE (actief = '1') ORDER BY volgorde LIMIT ?");
	$rs->bindParam(1, $limit, PDO::PARAM_INT);  // ERROR
	$rs->execute([$limit]);	
	while ($row = $rs->fetch()){
		$results_array[] = $row;
	}	
	return $results_array;
}

Gives me this error and I don't understand why.
Error: Class 'ProcessWire\PDO' not found

Anyone?  I suspect PDO::PARAM_INT ?

Link to comment
Share on other sites

The problem is that PDO is outside the PW namespace, which is why the "\" is necessary to get you to the global namespace. That change definitely works for me.

But then you'll get an error with the way you have your execute([$limit]);

I would go with this version instead:

function getKappers($limit = 10) {
    $rs = wire('database')->prepare("SELECT * FROM appointment_kapper WHERE (actief = '1') ORDER BY volgorde LIMIT :limit");
    $rs->bindParam(':limit', $limit, \PDO::PARAM_INT);
    $rs->setFetchMode(\PDO::FETCH_ASSOC);
    $rs->execute();
    return $rs->fetchAll();
}

Note that I also used FETCH_ASSOC so you automatically get an array back without needing to iterate the results to build it up.

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...