title: How to fix "Error SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. "
body: <p>I'm trying to connect my web application to sql server database but getting an error.</p>
  
  <p>This is my first project in mvc. Please check if there's a problem in my coding pattern.</p>
  
  <p>Controller: hello.php</p>
  
  <pre><code> class Hello  
   {
  
     public function _construct()
     {
      parent::construct();
     }
     public static function index() 
     {        
      $this-&gt;view-&gt;allrecords = $this-&gt;Index_model-&gt;getAllrecords();
      $this-&gt;view-&gt;render('views/index');
  
      }
  
   }
  </code></pre>
  
  <p>lib: Db.class</p>
  
  <pre><code>class Db {
  
  public static $db;
  
  const SERVER = "";
  const SCHEMA = "";
  const USER = "";
  const PASS = "";
  
  
  
  public static function databaseConnection() {
      if (!self::$db) {
          try {
  
              $databse = "sqlsrv:server=" . self::SERVER . ";Database=" . self::SCHEMA;
              self::$db = new PDO($databse, DB::USER, DB::PASS);
              self::$db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
          } catch (PDOException $e) {
              die("Error " . $e-&gt;getMessage());
          }
      }
      return self::$db;
  }
  
   }
  </code></pre>
  
  <p>Model: index_model.php</p>
  
  <pre><code>&lt;?php
  require_once '../lib/Db.class';
  
  class Index_model 
   {
  public static function _construct() {
  
      parent::_construct();
  
     }
  
    public static function getAllrecords(){
      $db = Db::databaseConnection();
      $sql = "SELECT Goals from Goals";
      $stmt = $db-&gt;conn-&gt;prepare($sql);
      $stmt-&gt;execute();
      $data = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
      return $data;
     }
   }
  </code></pre>
  
  <p>View: index.php</p>
  
  <pre><code>&lt;?php
  require_once '../models/index_model.php';
  require_once '../controllers/hello.php';
  ?&gt;
  
  &lt;table border="2" id="internalActivities" style="width:100%" class="table 
  table-bordered"&gt;
      &lt;tbody&gt;
         &lt;tr&gt;
  &lt;th&gt;Goals&lt;/th&gt;  
   &lt;?php echo Index_model::getAllrecords(); ?&gt;
    &lt;/tr&gt;     
  &lt;/tbody&gt;
  </code></pre>
  
  <p>I'm not sure where exactly the error could be. I've been using the same code for connection in my other apps. It's just that I'm using it in mvc pattern so maybe there's error in the pattern. 
  I want to display a list of Goals in the Goals table. </p>