Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > บทความจากสมาชิก > Config PHP for SQL Server 2005/2008 Express (Windows 7 32-bit , Windows 7 64-bit)



 
Clound SSD Virtual Server

Config PHP for SQL Server 2005/2008 Express (Windows 7 32-bit , Windows 7 64-bit)

Config PHP for SQL Express 2005/2008 (Windows 7 32-bit , Windows 7 64-bit) บทความ PHP กับฐานข้อมูล SQLExpress (SQL Server Express) ซึ่งเป็น Version ที่สามารถดาวน์โหลดและใช้งานได้ฟรี ตัวอย่างการ Config ให้สามารถเรียกใช้ function mssql() และการเชื่อมต่อกับฐานข้อมูล ตัวอย่างนี้ใช้ได้ทั้ง SQL Server 2005 Express และ SQL Server 2008 Express

พอดีเห็นถามกันบ่อยๆ เกี่ยวกับ PHP และ SQL Express วันนี้เลยจัดทำบทความให้ซะหน่อย ซึ่งอันที่จริงและก็ไม่ต่างอะไรกับ SQL Server รุ่นปกติที่ใช้กันทั่ว ๆ ไป

โดยขั้นแรกให้ตรวจสอบ php.ini ว่ารองรับ function mssql() หรือยัง โดยใช้คำสั่ง phpinfo();

phpinfo();


Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)

ถ้าสามารถใช้ function mssql() ได้จะขึ้นเหมือนในรูป แต่ถ้าไม่มีให้ทำตามขั้นตอนดังต่อไปนี้

sqlexpress.php
<html>
<head>
<title>ThaiCreate.Com Tutorials</title>
</head>
<body>
<?php
	$objConnect = mssql_connect(".\SQLEXPRESS","","");
	if($objConnect)
	{
		echo "Database Connected.";
	}
	else
	{
		echo "Database Connect Failed.";
	}

	mssql_close($objConnect);
?>
</body>
</html>


เขียนคำสั่งเชื่อมต่อกับฐานข้อมูลเหมือนในตัวอย่าง โดยใช้ Instance Name ให้ถูกต้อง
ปกติจะใช้ SERVER-NAME\SQLEXPRESS หรือ .\SQLEXPRESS

(SQL Server 2005 Express และ SQL Server 2008 Express ใช้เหมือนกัน)

Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)

รูปการใช้การเชื่อมต่อผ่าน Instance ของ SQL Server Express จะเห็นว่ามีการใช้ Instance ว่า .\SQLEXPRESS

หลังจากสร้างไฟล์เรียบร้อยแล้ว ให้ทดสอบการเชื่อมต่อ

Error Case 1
Fatal error: Call to undefined function mssql_connect() in C:\AppServ\www\myphp\sqlexpress.php on line 6


ข้อผิดพลาดนี้เกิดจาก php ยังไม่ได้เปิดการใช้งาน extension ของ mssql การแก้ไขให้เปิด extension ของ mssql ด้วยการ ให้ทำการดาวน์โหลดตัว extension ชื่อ php_mssql.dll

php_mssql.dll



ไปไว้ในโฟเดอร์ extension ของ php เช่น C:\AppServ\php5\ext หรือสามารถตรวจสอบ Path ได้ที่ php.ini


Start -> Run -> php.ini

extension_dir = "C:/AppServ\php5\ext"
.
.
.
.
.
extension=php_mssql.dll


เปิดด้วยการลบ ; ออก เฉพาะฉะนั้นจะเหลือแค่ extension=php_mssql.dll หรือถ้าไม่มีก็ให้เพิ่มบรรทัดนี้เข้าไป

จากนั้น ให้ทำการ save ไฟล์ php.ini พร้อมกับ Restart Apache หนึ่งรอบ จากนั้นให้ลองใหม่อีกครั้ง








Error Case 2
หลังจากเปิด extension=php_mssql.dll ยังไม่สามารถใช้งานได้ ให้ลองตรวจสอบ Log ของ Apache โดยไปที่ C:\AppServ\Apache2.2\logs\error.log

จะเห็นว่ามี Error
PHP Warning: PHP Startup: Unable to load dynamic library 'C:/AppServ\\php5\\ext\\php_mssql.dll' - The specified module could not be found.\r\n in Unknown on line 0


วิธีการแก้ไข



Windows 7 32-bit
Copy ntwdblib.dll ไปไว้ที่ C:\Windows\system32\

Windows 7 64-bit
Copy ntwdblib.dll ไปไว้ที่ C:\Windows\SysWOW64\


และก็ Restart Apache หรือ Web Server ถ้าไม่มีอะไรผิดพลาดขั้นตอนนี้จะสามารถผ่านไปได้ โดยให้ตรวจสอบ Error log ที่ C:\AppServ\Apache2.2\logs\error.log ว่ามี extension ที่โหลดไม่สมบูรณ์หรือไม่


Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)

การเชื่อมต่อสมบูรณ์



และก็ทดลองการเชื่อมต่อใหม่อีกครั้ง ถ้าไม่มีอะไรผิดพลาดจะสามารถใช้งานได้ ส่วนการเชื่อมต่อกับ Database หรือ การ Insert/Update/Delete ข้อมูลใน SQL Express สามารถดูตัวอย่างได้จากบทความ PHP กับ SQL Server ซึ่งจะใช้รูปแบบคำสั่งเหมือนกันทุกประการ

Go to : PHP SQL Server : Connect to Microsoft SQL Server ภาษา PHP กับฐานข้อมูล SQL Server
Go to : PHP and SQL Server 2005
Go to : PHP and SQL Server 2008


การตรวจสอบการตั้งค่าอื่น ๆ ของ SQL Express

1.ตรวจสอบ Service ของ SQLExpress ว่าทำงานอยู่หรือไม่
Control Panel\All Control Panel Items\Administrative Tools



Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)

Service จะต้องอยู่ในสถานะ Start

2.ตรวจสอบ Protocal Name และ Status
Start menu -> Programs - > SQL Server... \... SQL Server Configuration Manager


Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)

ทำการ Enabled ตัว Shared Menu , Named Pices , TCP/IP (ปกติเปิด TCP/IP น่าจะพอเพื่อให้สามารถเรียกผ่าน Lan ได้)


2.ตรวจสอบ SQL Server Surface Area Configuration
Start menu -> Programs - > SQL Server... \... SQL Server Surface Area Configuration


Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)

คลิกที่ Surface Area Configuration for Services and Connections

Config PHP for SQL Server Express (Windows 7 32-bit , Windows 7 64-bit)


ปรับแต่ง บน Tree Database Engine -> Remote Connections -> Local and remote connections -> Using TCP/IP only เพื่อให้สามารถเรียกใช้งานผ่าน Lan ได้

ถ้าลองปรับแต่งตามบทความแล้ว ยังไม่ได้ ให้ลองนำ Error สอบถามได้ที่กระทู้บทความครับ


(ตัวอย่างนี้ใช้ได้ทั้งSQL Server 2005 Express , SQL Server 2008 Express หรือรุ่นอื่น ๆ ใช้เหมือนกัน)








บทความอื่น ๆ ที่เกี่ยวข้อง
Go to : php ติดต่อกับ sql server 2008 ไม่ได้ครับ search ดูแล้วลองทำหมดแล้วครับ windows7 64bit
Go to : Windows 64-bit =andgt; PHP ติดต่อกับ MSSQL ไม่ได้ค่ะ Call to undefined function mssql_connect
Go to : ผมลงวินโดว์ใหม่ เป็นวินโดว์ 7 64 bit เชื่อมต่อกับฐานข้อมูล mssql server ไม่ได้ครับ ขึ้น Fatal error: Call to undefined function mssql_connect() in ...


   
Share
Bookmark.   

  By : TC Admin
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2011-09-30
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่