<?php
function DB_conn($db_option){
  $addr   = "{$db_option['database_host']},{$db_option['database_port']}";
  $option = Array(
    "Database"     => $db_option['database_name'],
    "Uid"          => $db_option['database_user'],
    "PWD"          => $db_option['database_pass'],
    "CharacterSet" => $db_option['database_encode'],
  );
  if( $db_option['database_old'] ){
    $option['Encrypt'] = "yes";
    $option['TrustServerCertificate'] = "yes";
  }
  $conn = sqlsrv_connect( $addr, $option);
  if( $conn ){
    return $conn;
  }else{
    die('Could not connect: ' . print_r(sqlsrv_errors(), true));
  }
}

function sqlsrv_qry($conn, $tsql, $params=Array(), $options=Array()){
  $stmt = @sqlsrv_query($conn, $tsql, $params, $options);
  if( $stmt ) return $stmt;
  else {
    echo "<pre>".print_r(sqlsrv_errors(), true)."</pre>";
    return false;
  }
}

//에러 처리용으로 하나만 만들고 기본 예약함수만 쓴다.