|
 |
|
ขอความช่วยเหลือเกี่ยวกับ การเปลี่ยนฐานข้อมูลจาก MySQL มาเป็น Ms SQLServer 2005 ของ code ตัวนี้ครับ |
|
 |
|
|
 |
 |
|
ขอความช่วยเหลือเกี่ยวกับ การเปลี่ยนฐานข้อมูลจาก MySQL มาเป็น Ms SQLServer 2005 ของ code ตัวนี้ครับ
Code (PHP)
<?php
/* API Connection TMTopup for Dadteam.Com*/
/*
* Modify by Nst Interactive [http://www.nstinteractive.com/]
*/
# ------------------------------------- Config Begin ------------------------------------- #
// ------------------------------------------------------------------------------------------------
/* MySQL Config | Begin */
// Hostname ของ MySQL Server
$_CONFIG['mysql']['dbhost'] = 'localhost';
// Username ที่ใช้เชื่อมต่อ MySQL Server
$_CONFIG['mysql']['dbuser'] = 'username';
// Password ที่ใช้เชื่อมต่อ MySQL Server
$_CONFIG['mysql']['dbpw'] = 'password';
// ชื่อฐานข้อมูลที่เราจะเติม Point ให้
$_CONFIG['mysql']['dbname'] = 'gta';
// ชื่อตารางที่เราจะเติม Point ให้ ตัวอย่าง : member
$_CONFIG['mysql']['tbname'] = 'member';
// ชื่อ field ที่ใช้อ้าง Username
$_CONFIG['mysql']['field_username'] = 'username';
// ชื่อ field ที่ใช้ในการเก็บ Point จากการเติมเงิน
$_CONFIG['TMN']['point_field_name'] = 'point';
/* MySQL Config | End */
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
/* จำนวน Point ที่จะได้รับเมื่อเติมเงินในราคาต่างๆ | Begin */
$_CONFIG['TMN'][50]['point'] = 500; // Point ที่ได้รับเมื่อเติมเงินราคา 50 บาท
$_CONFIG['TMN'][90]['point'] = 900; // Point ที่ได้รับเมื่อเติมเงินราคา 90 บาท
$_CONFIG['TMN'][150]['point'] = 1500; // Point ที่ได้รับเมื่อเติมเงินราคา 150 บาท
$_CONFIG['TMN'][300]['point'] = 3000; // Point ที่ได้รับเมื่อเติมเงินราคา 300 บาท
$_CONFIG['TMN'][500]['point'] = 5000; // Point ที่ได้รับเมื่อเติมเงินราคา 500 บาท
$_CONFIG['TMN'][1000]['point'] = 10000; // Point ที่ได้รับเมื่อเติมเงินราคา 1,000 บาท
/* จำนวน Point ที่จะได้รับเมื่อเติมเงินในราคาต่างๆ | End */
// ------------------------------------------------------------------------------------------------
// กำหนด API Passkey
define('API_PASSKEY', 'NSTPasskey01');
# -------------------------------------- Config End -------------------------------------- #
require_once('AES.php');
// ------------------------------------------------------------------------------------------------
/* เชื่อมต่อฐานข้อมูล | Begin */
mysql_connect($_CONFIG['mysql']['dbhost'],$_CONFIG['mysql']['dbuser'],$_CONFIG['mysql']['dbpw']) or die('ERROR|DB_CONN_ERROR|' . mysql_error());
mysql_select_db($_CONFIG['mysql']['dbname']) or die('ERROR|DB_SEL_ERROR|' . mysql_error());
/* เชื่อมต่อฐานข้อมูล | End */
// ------------------------------------------------------------------------------------------------
if($_SERVER['REMOTE_ADDR'] == '203.146.127.115' && isset($_GET['request']))
{
$aes = new Crypt_AES();
$aes->setKey(API_PASSKEY);
$_GET['request'] = base64_decode(strtr($_GET['request'], '-_,', '+/='));
$_GET['request'] = $aes->decrypt($_GET['request']);
if($_GET['request'] != false)
{
parse_str($_GET['request'],$request);
$request['Ref1'] = base64_decode($request['Ref1']);
/* Database connection | Begin */
$result = mysql_query('SELECT * FROM `'. $_CONFIG['mysql']['tbname'] .'` WHERE `'. $_CONFIG['mysql']['field_username'] .'`=\'' . mysql_real_escape_string($request['Ref1']) . '\' LIMIT 1') or die(mysql_error());
if(mysql_num_rows($result) == 1)
{
$row = mysql_fetch_assoc($result);
if(mysql_query("UPDATE `". $_CONFIG['mysql']['tbname'] ."` SET `". $_CONFIG['TMN']['point_field_name'] ."` = `". $_CONFIG['TMN']['point_field_name'] ."`+'". $_CONFIG['TMN'][$request['cardcard_amount']]['point'] ."' WHERE `". $_CONFIG['mysql']['field_username'] ."` = '". $row[$_CONFIG['mysql']['field_username']] ."' LIMIT 1 ") == false)
{
echo 'ERROR|MYSQL_UDT_ERROR|' . mysql_error();
}
else
{
echo 'SUCCEED|UID=' . $row[$_CONFIG['mysql']['field_username']];
}
}
else
{
echo 'ERROR|INCORRECT_USERNAME';
}
/* Database connection | End */
}
else
{
echo 'ERROR|INVALID_PASSKEY';
}
}
else
{
echo 'ERROR|ACCESS_DENIED';
}
?>
ขอความกรุณาด้วยครับ
Tag : PHP, MySQL, Ms SQL Server 2005

|
|
 |
 |
 |
 |
Date :
2012-06-01 08:42:43 |
By :
forkawasaki |
View :
1567 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้จะใช้ได้ไหมครับ พอดีผมเพิ่งหัดเรียนรู้ PHP ครับ Code ก็เลยยังไม่ค่อยแน่ใจครับ จึงอยากขอคำชี้แน่ะจากพี่ๆครับ
Code (PHP)
<?php
/* API Connection TMTopup for Dadteam.Com*/
/*
* Modify by Nst Interactive [http://www.nstinteractive.com/]
*/
# ------------------------------------- Config Begin ------------------------------------- #
// ------------------------------------------------------------------------------------------------
/* MySQL Config | Begin */
// Hostname ของ MySQL Server
$_CONFIG['mssql']['dbhost'] = 'localhost';
// Username ที่ใช้เชื่อมต่อ MySQL Server
$_CONFIG['mssql']['dbuser'] = 'username';
// Password ที่ใช้เชื่อมต่อ MySQL Server
$_CONFIG['mssql']['dbpw'] = 'password';
// ชื่อฐานข้อมูลที่เราจะเติม Point ให้
$_CONFIG['mssql']['dbname'] = 'gta';
// ชื่อตารางที่เราจะเติม Point ให้ ตัวอย่าง : member
$_CONFIG['mssql']['tbname'] = 'member';
// ชื่อ field ที่ใช้อ้าง Username
$_CONFIG['mssql']['field_username'] = 'username';
// ชื่อ field ที่ใช้ในการเก็บ Point จากการเติมเงิน
$_CONFIG['TMN']['point_field_name'] = 'point';
/* MySQL Config | End */
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
/* จำนวน Point ที่จะได้รับเมื่อเติมเงินในราคาต่างๆ | Begin */
$_CONFIG['TMN'][50]['point'] = 500; // Point ที่ได้รับเมื่อเติมเงินราคา 50 บาท
$_CONFIG['TMN'][90]['point'] = 900; // Point ที่ได้รับเมื่อเติมเงินราคา 90 บาท
$_CONFIG['TMN'][150]['point'] = 1500; // Point ที่ได้รับเมื่อเติมเงินราคา 150 บาท
$_CONFIG['TMN'][300]['point'] = 3000; // Point ที่ได้รับเมื่อเติมเงินราคา 300 บาท
$_CONFIG['TMN'][500]['point'] = 5000; // Point ที่ได้รับเมื่อเติมเงินราคา 500 บาท
$_CONFIG['TMN'][1000]['point'] = 10000; // Point ที่ได้รับเมื่อเติมเงินราคา 1,000 บาท
/* จำนวน Point ที่จะได้รับเมื่อเติมเงินในราคาต่างๆ | End */
// ------------------------------------------------------------------------------------------------
// กำหนด API Passkey
define('API_PASSKEY', 'NSTPasskey01');
# -------------------------------------- Config End -------------------------------------- #
require_once('AES.php');
// ------------------------------------------------------------------------------------------------
/* เชื่อมต่อฐานข้อมูล | Begin */
mssql_connect($_CONFIG['mssql']['dbhost'],$_CONFIG['mssql']['dbuser'],$_CONFIG['mssql']['dbpw']) or die('ERROR|DB_CONN_ERROR|' . mssql_error());
mssql_select_db($_CONFIG['mssql']['dbname']) or die('ERROR|DB_SEL_ERROR|' . mssql_error());
/* เชื่อมต่อฐานข้อมูล | End */
// ------------------------------------------------------------------------------------------------
if($_SERVER['REMOTE_ADDR'] == '203.146.127.115' && isset($_GET['request']))
{
$aes = new Crypt_AES();
$aes->setKey(API_PASSKEY);
$_GET['request'] = base64_decode(strtr($_GET['request'], '-_,', '+/='));
$_GET['request'] = $aes->decrypt($_GET['request']);
if($_GET['request'] != false)
{
parse_str($_GET['request'],$request);
$request['Ref1'] = base64_decode($request['Ref1']);
/* Database connection | Begin */
$result = mssql_query('SELECT * FROM `'. $_CONFIG['mssql']['tbname'] .'` WHERE `'. $_CONFIG['mssql']['field_username'] .'`=\'' . mssql_real_escape_string($request['Ref1']) . '\' LIMIT 1') or die(mssql_error());
if(mssql_num_rows($result) == 1)
{
$row = mssql_fetch_assoc($result);
if(mssql_query("UPDATE `". $_CONFIG['mssql']['tbname'] ."` SET `". $_CONFIG['TMN']['point_field_name'] ."` = `". $_CONFIG['TMN']['point_field_name'] ."`+'". $_CONFIG['TMN'][$request['cardcard_amount']]['point'] ."' WHERE `". $_CONFIG['mssql']['field_username'] ."` = '". $row[$_CONFIG['mssql']['field_username']] ."' LIMIT 1 ") == false)
{
echo 'ERROR|MYSQL_UDT_ERROR|' . mssql_error();
}
else
{
echo 'SUCCEED|UID=' . $row[$_CONFIG['mssql']['field_username']];
}
}
else
{
echo 'ERROR|INCORRECT_USERNAME';
}
/* Database connection | End */
}
else
{
echo 'ERROR|INVALID_PASSKEY';
}
}
else
{
echo 'ERROR|ACCESS_DENIED';
}
?>
ขอขอบคุณสำหรับทุกคำตอบครับป๋ม
|
ประวัติการแก้ไข 2012-06-01 11:55:01 2012-06-01 12:08:02
 |
 |
 |
 |
Date :
2012-06-01 11:53:44 |
By :
forkawasaki |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันที่จริง function ใน mysql และ mssql มันใช้ได้ทันทีน่ะครับ แค่เปลี่ยนให้ถูกต้องครับ 
|
 |
 |
 |
 |
Date :
2012-06-01 13:02:50 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ เดี๋ยวผมจะลองทดสอบดูครับ ^_^
|
 |
 |
 |
 |
Date :
2012-06-01 14:49:53 |
By :
forkawasaki |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|