I have the following function which enables a query to run with a where condition. But it seems not to be producing any results.
I can connect to the database so that is not an issue.
Any help would be appreciated.
public function executewhereQuery(Array $tableData, $fieldType, $table, $tableField){
$dbh = $this->connect();
try{
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** fetch into an PDOStatement object ***/
$stmt = $dbh->prepare("SELECT * FROM ".$table."
WHERE ".$tableField." = :fieldValue");
if($fieldType=='int'){
$stmt->bindParam(':fieldValue', $fieldValue, PDO::PARAM_INT);
}
else{
$stmt->bindParam(':fieldValue', $fieldValue, PDO::PARAM_STR);
}
$stmt->execute($tableData);
/*** fetch the results ***/
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $results;
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e){
echo $e->getMessage();
}
}
I am calling the function using the following:
$mydb = new Dbpdo_Database();
$tableData = Array('fieldValue' => 1);
$table = 'news';
$tableField = 'newsID';
$fieldType = 'int';
$results = $mydb->executewhereQuery($tableData, $fieldType, $table, $tableField);
foreach ($results as $row){
echo $row['newsTitle'].'-'.$row['newsText1'].'<br />';
}