M
M
Mr. Abdu Jan2013-11-15 15:04:12
PHP
Mr. Abdu Jan, 2013-11-15 15:04:12

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();
            }

        }

When I use a query with a condition (string-cyrillic) does not display the result.
$authArr = $DBH->select("   SELECT
                                        id_tip_tovar
                                    FROM
                                        skladskiy_uchet.dbo.spr_tip_tovar
                                    WHERE
                                        tip_tovar = N'Тип товар 1'");

What could be the problem?
Thanks....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Skahin, 2013-11-15
@pihel

Different encodings of application and DB? Why is bindValue not used yet, if possible, but a parameter is substituted directly into the request?

P
Peter, 2013-11-15
@Alcospb

And this SQL query is triggered by direct access to the database?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question