title: SELECT in Php with PDO (dblib) to SQL view
body: <p>I am trying to execute a SQL query and it does not work.</p>
  
  <pre><code>$sql = "SELECT top 5 AccountDocument from web.Preoffers_new where AccountDocument = 'xxxxxxxx'";
  $stmt = $db-&gt;prepare($sql);
  $stmt-&gt;execute();
  
  if ($data = $stmt-&gt;fetch()) {
      do {
          echo $data['AccountDocument'] . '&lt;br&gt;';
      } while ($data = $stmt-&gt;fetch());
  } else {
      echo 'Empty Query';
  }
  </code></pre>
  
  <p>This works perfectly and shows me the results.</p>
  
  <p>But this:</p>
  
  <pre><code>$sql = "SELECT top 5 Document from Companies where Document = 'xxxxxxxx'";
  $stmt = $db-&gt;prepare($sql);
  $stmt-&gt;execute();
  
  if ($data = $stmt-&gt;fetch()) {
      do {
          echo $data['Document'] . '&lt;br&gt;';
      } while ($data = $stmt-&gt;fetch());
  } else {
      echo 'Empty Query';
  }
  </code></pre>
  
  <p>Go directly to Empty Query. But is not true because if I execute that query in SQL it works perfectly.</p>
  
  <p>The only diferent i see is the first one query go to a table in the DB and the second one go to a one view...</p>
  
  <p>Some clues could be this?</p>
  
  <pre><code>    SET 
    ANSI_NULLS, 
    QUOTED_IDENTIFIER, 
    CONCAT_NULL_YIELDS_NULL, 
    ANSI_WARNINGS, 
    ANSI_PADDING 
  ON;
  </code></pre>
  
  <p><strong>UPDATE ----></strong></p>
  
  <p>i set the attribute <strong>PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION</strong> for see if the server show me something and I received this:</p>
  
  <p><strong>Error conectando con la base de datos: SQLSTATE[HY000]: General error: 1934 General SQL Server error: Check messages from the SQL Server [1934] (severity 16) [SELECT top 5 Document from Companies where Document = 'xxxxxxxx']</strong></p>
  
  <p>I checked the error in SQL and I get this:</p>
  
  <p><strong>%ls failed because the following SET options have incorrect settings: '%.*ls'. Verify that SET options are correct for use with %S_MSG..</strong></p>
  
  <p>Anyone have any idea why I can not make queries in views?</p>
  
  <p>Thanks for reading me :)</p>