У меня есть следующая функция, которая позволяет выполнить запрос с условием where. Но, похоже, не дает никаких результатов.
Я могу подключиться к базе данных, так что это не проблема.
Любая помощь будет оценена.
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();
}
}
Я вызываю функцию, используя следующее:
$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 />';
}