Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] Connect to your DB with PHP

Newbie Spellweaver
Joined
Dec 15, 2010
Messages
6
Reaction score
2
Hello world !

This tutorial will show you how to connect on your Pangya_S4_TH DB with PHP

Step
1 - Configure Server SQL
2 - Configure PHP
3 - Connection and SQL query test

What you need :
1) Microsoft Server SQL
2) Pangya_S4_TH installed


1 - Configure Server SQL

Execute "SQL Server Configuration Manager" ( )

Go to "SQL Server Network Configuration" then on "Protocols for MSSQLSERVER"
Enable Named Pipes and TCP/IP by right click -> Enable ( )

Right click on TCP/IP => Properties
Protocol Tab => Listen All => Yes ( )
IP Addresses Tab => IPAll => TCP Port => 1433 ( )

Make sure Named Pipes and TCP/IP are Enabled in "SQL Native Client 10.0 Configuration" => "Client Protocols"
NB : If you have a 64 bits windows, you will have 2 "SQL Native Client 10.0 Configuration", one for 32 bits, and one for 64 bits

Go to "SQL Server Services"
Right click on "SQL Server (MSSQLSERVER)" => Restart ( )

SQL Configuration finished !

2 - Configure PHP

Install php_pdo_odbc extension for PHP
if you have WAMP/EasyPHP, you just have to delete the ";" in front of the line "extension=php_pdo_odbc.dll" in php.ini

Restart apache

PHP Configuration finished !

3 - Connection and SQL query test

Now it's time to test !

PHP:
<?php

	$server = '127.0.0.1';
	$database = 'Pangya_S4_TH';
	$user = 'sa';
	$passwd = '*****'; //Replace ***** by your passwd

	$connect = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $passwd);

	$sql = '...'; //Replace ... by the SQL query

	$result = odbc_exec($connect, $sql;
	
	while($array = odbc_fetch_array($result)) {
		foreach($array as $key => $value) {
			echo $key . " : " . $value . "<br/>";
		}
		echo '<br/><br/>';
	}
	
?>

I did this SQL query to test : SELECT * FROM [Pangya_S4_TH].[dbo].[Pangya_Item_WareHouse] and it work perfectly

I hope it will help some of you to make a website to manage your Pangya Server ;)
 
Deny everything.
Joined
Jun 17, 2005
Messages
488
Reaction score
110
Easy to follow, captures all important steps and right to the point. Excellent!

For all curious minds: Be sure to check out that adds things like unicode support and other cool stuff while you're at it. :)
 
Experienced Elementalist
Joined
Aug 10, 2008
Messages
291
Reaction score
10
had a hard time with my site before but this would make it a lot easier for people trying to make their own tools for the DB.
 
Back
Top