Answer the question
In order to leave comments, you need to log in
How to make conditional data output from MS SQL Server 2005 via PDO?
Hello everyone,
I'm facing the same problem. You need to retrieve data from the database using PDO. There is a custom class with functions that display data.
public function select($sql, $array = array(), $fetchMode = PDO::FETCH_ASSOC)
{
//try... if not catch exception
try{
$sth = $this->DBH_->prepare($sql);
foreach ($array as $key => $value) {
$sth->bindValue("$key", $value); // bind parameters - avoids SQL injection
}
// run the query
$sth->execute();
return $sth->fetchAll($fetchMode);
}
catch(PDOException $e) {
echo "<p class='error_msg'>Ошибка. Свяжитесь с программистами.</p>";
file_put_contents('errors.log', date("Y-m-d H:i:s")." - ".$e->getMessage().". File:".$e->getFile().". Line: ".$e->getLine()."\n", FILE_APPEND);
exit();
}
}
$authArr = $DBH->select(" SELECT
id_tip_tovar
FROM
skladskiy_uchet.dbo.spr_tip_tovar
WHERE
tip_tovar = N'Тип товар 1'");
Answer the question
In order to leave comments, you need to log in
Different encodings of application and DB? Why is bindValue not used yet, if possible, but a parameter is substituted directly into the request?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question