I would like to setup an array with multiple parameters in it, pass it to my database class. Currently I can only send one parameter, but generally my sql queries have multiple parameters.
Sample database method:
public function fetchQuery($sql,$params,$conn){
try{
$queryparams=array($params);
$x=$conn->prepare($sql);
$x->execute($queryparams);
$rArray = $x->fetchAll(PDO::FETCH_ASSOC);
return $rArray;
}catch (Exception $e){
die( print_r( $e->getMessage() ) );
}
}
Call to database method:
$params=$vendID;
$sql = "SELECT Email from Contact WHERE VendID = ?";
try{
$emails=$db->fetchQuery($sql,$params,$conn);
$eCount = count($emails);
if($eCount>0){
foreach($emails as $row){
$eArray[]=$row['Email'];
}
}else{
echo "No email addresses associated with this vendor";
}
}
catch(Exception $e){
die( print_r( $e->getMessage() ) );
}
Now say my sql query was like: "Select * from Contact where CustID=? and Expired=?" How would I build an array and pass the into my function?
Every time I try, I get an array to string conversion error.
Thanks