ติดตั้ง Server 2012 R2
Host จริงแนะนำ OS ให้เป็น Server (ในที่นี่ผมใช้ SERVER 2012 R2)
คลิก Next
เลือก Server with a GUI
เลือก Custom: Install Windows Only
New->Format คลิก Next
Installing...
ตั้งรหัสผ่าน
จบขั้นตอนติดตัั้ง SERVER 2012 R2 แบบ Basic
SQL SERVER Configuration Manager
-เปิด SQL SERVER Configuration Manager ขึ้นมา
-Start Service: SQL SERVER (SQLEXPRESS), SQL SERVER BROWSER ตามรูป
คลิกขวาที่ SQL Server BROWSER \ Properties ไปที่ Tap: Service->Start Mode เลือก Automatic
ตั้งค่า Network Configuration: ที่หัวข้อ SQL Server Network Configuration
ให้ Enabled 3 Protocal ตามรูป
ตั้งค่า TCP/IP: คลิกขวา->Properties->ที่ Tap: IP Addresses
กำหนด TCP Port: 1433 ทุกหัวข้อ IP
ที่หัวข้อ IPALL
TCP Dynamic Ports: ว่าง
ตั้งค่า Firewall: Control Panel->Windows Firewall->Advance Settings->Inbound Rules
-New Rule->Port คลิก Next
-Specific Local Ports: 1433
-คลิก Next, Next, Next ตั้งค่า Name: Allow SQL Server
เริ่มใช้งาน SQL Server Management Studio (SSMS)
SQL Server Management Studio ขอเรียกสั้นๆว่า SSMS
-เปิดโปรแกรมขึ้นมา Authentication: เลือก Windows Authentication ไปก่อน
-ตั้งค่า SQL SERVER + Windows Authen:
-คลิกว่าที่ SQL SERVER->Properties
-ที่หัวข้อ Security: เลือก SQL Server and Windows Authentication mode ตามรูป
Add new User:
-ที่หัวข้อ Security: คลิกขวา->New Login
-กรอก Login Name: admin
-ติ๊กเครื่องหมายถูกที่หน้า Enforce Password Policy ออก
-กำหนด Server Rules, User Mapping
-status->login: Enabled
-Restart Service 1 รอบ
-จากนั้นทดสอบ Login จากเครื่องในวง LAN: SQL Server Mode
-ตั้ง SSMS เพิ่มเติม: เพื่อให้สามารถ Save แก้ไข Table ได้
-Tools->Options...
-Designer: Table and Database Designers
ติ๊กเครื่องหมายถูกที่หน้า: Prevent saving changes that require table re-creation ออก
ทดสอบ สร้าง Database:
-Create Database: คลิกขวา Database->New Database...
ตั้งชื่อ Database name: test
-
ตั้งค่า Options->Collation: Thai_CI_AS
-คลิก OK
ทดสอบ Connect: ที่ Controller เขียนแบบง่ายละกัน ใช้คำสั่ง Active Record เหมือน MySQL เลยครับ
ตัว Test ผมเขียน Query ที่ Controller เลยละกัน (ปกติจะนิยมเขียนที่ Model) Code (PHP)
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Test extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$data['data'] = $this->db->query("SELECT * FROM exam")->result();
$this->load->view('test_view', $data);
}
}