How to make an output with the condition of MS SQL Server 2005 via PDO?

Hi all,

Faced with such a problem. Need to get data from a database using PDO. You have user class with functions that output the 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">Error. Contact programmers.</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();
}

 }


When I use the query with the condition (string is Cyrillic) does not output the result.
$authArr = $DBH->select(" SELECT
id_tip_tovar
FROM
skladskiy_uchet.dbo.spr_tip_tovar
WHERE
 tip_tovar = N Type of product 1'");


What could be the problem?
Thank you....

October 3rd 19 at 02:05
2 answers
October 3rd 19 at 02:07

Different encodings of the application and the database? Why not use bindValue, if possible, and is substituted directly into the query parameter?

bindValue is used in a foreach loop - dusty_Kuhic42 commented on October 3rd 19 at 02:10
bindValue is NOT used in a foreach loop. - lafayette_Pouros commented on October 3rd 19 at 02:13
foreach ($array as $key => $value) { $sth->bindValue("$key", $value); } - dusty_Kuhic42 commented on October 3rd 19 at 02:16
foreach ($array as $key => $value) { $sth->bindValue("$key", $value); } - dusty_Kuhic42 commented on October 3rd 19 at 02:19
it is impossible SO to understand what makes your own code. bindValue in this example not used. - lafayette_Pouros commented on October 3rd 19 at 02:22
Yes, I know that this example is not used.... because the condition is already written... when using and not using bindValue still does not display the result kirilica. - dusty_Kuhic42 commented on October 3rd 19 at 02:25
October 3rd 19 at 02:09

And this SQL query is triggered when a direct appeal to the base?

Yes, it works. - dusty_Kuhic42 commented on October 3rd 19 at 02:12

Find more questions by tags PHPSQLPHP PDO