So I'm trying to create a function to execute PDO statements for me, per your guys' suggestion to switch from mysql. The issue is, when I add more than one param, I get no results back. Here is my function
//this function takes in a sql statement and an array of parameter names and values
//and returns the 2d array of the mysql data
function fetchRows($sql, $paramArr){
$pdo = connect();
$statement = $pdo->prepare($sql);
//if there's anything in the array loop through and bind the params
foreach ($paramArr as $key=>$i)
{
echo($key . " => " . $i ." test<br />");
$statement->bindParam($key, $i);
}
$statement->execute();
//get's 1 record
//$row = $statement->fetch(PDO::FETCH_ASSOC);
//get's all
return($statement->fetchAll());
}//getData
Now here is the code I'm testing, you can see running either of the two statements with one parameter works, but when I try to add both, it doesn't.
//this one doesn't work
$params = array(":type"=>"2", ":name"=>"testuser1");
$sql = "SELECT * FROM users WHERE userType=:type AND username=:name;";
//this one works
//$params = array(":name"=>"testuser1");
//$sql = "SELECT * FROM users WHERE username=:name;";
//this one works too
//$params = array(":type"=>"2");
//$sql = "SELECT * FROM users WHERE userType=:type;";
$arr = fetchRows($sql, $params);
var_dump($arr);