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!

[Question] Mysql php convert Mssql php?

zet

Experienced Elementalist
Joined
Aug 25, 2010
Messages
251
Reaction score
24
good day to all i am new in php coding

i would like to ask every one here how to convert this mysql to mssql.php

PHP:
/****************************************************************************
File:   vote.php
Desc:   traces a vote creating a random key, and sends the vote.
****************************************************************************/
$listname = mysql_real_escape_string( $_REQUEST['listname'] );
 
// load data of rating site
$data = mysql_query( 
	"select id, voting_link 
  from cfg_ranking_sites
  where name = '{$listname}' " );
 
list( $list_id, $voting_link) = mysql_fetch_row( $data );
 
// generate a rnd string
$k =  substr( md5 ( time() . rand(1, 10000000) ), 1, 25);
 
// get the user id from session
// (substitute your method for finding the user id)
$user = User::get_char_info();
$u = $user['user_id'];
 
// place the generated random key and trace the vote
$urlcalled = str_replace( "KEY", $k, $voting_link );
 
mysql_query( "insert into 
	voting_log
  ( user_id, vkey, list_id, ip, status, urlcalled ) 
  values
  ( '{$u}', '{$k}', $list_id, '".$_SERVER['REMOTE_ADDR']."', 'new', '{$urlcalled}' ) ");
 
// send the vote
header ( "location: $urlcalled" );
exit;

PHP:
// Set content type
header('Content-type: text/xml');
// Check input, if keys are not present return error.
// This check and the fields needs to be changed for each toplist
if (
	!isset($_GET['key']) or 
	!isset($_GET['success']) or
	!isset($_GET['listname']) or
	) {
	echo '<response rewarded="0" message="Invalid input." />';
	die();
}
 
// Get data
$key = mysql_real_escape_string($_GET['key']);
$success = mysql_real_escape_string($_GET['success']);
$referer = $_SERVER['HTTP_REFERER'];
 
$sql = "select v.id, v.user_id, r.name
from voting_log v, cfg_ranking_sites r
where vkey = '{$key}' and v.list_id = r.id
and   refererurl = '{$referer}'
and   status = 'new'";
$data = mysql_query( $sql );
 
if ( mysql_num_rows( $data ) == 0 )
{
// insert your debug message, return error
// mydebug( true, "match not found. ip: " . $_SERVER['REMOTE_ADDR'] . " key: " . $key . " referer: " . $referer);
echo '<response rewarded="0" message="match not found." />';
exit;
}
 
list( $id, $user_id, $list_name ) = mysql_fetch_row( $data );
 
// give rewards to user, only if the vote was unique ($success==1)
if ( $success == 1 )
{
	$r = rand( 1,2 );
	if ( $r == 1 ) 
	{
		;
		//example: give reward and send information to user
		//mysql_query( "update user set char_adamantium = char_adamantium + 2 where user_id = " . $user_id );
		//User::send_news( 'char', $user_id, "You got 2 adamantium for your vote at " . $list_name );
	}
 
	else
	{
		;
		//example: give reward and send information to user
		//mysql_query( "update user set char_mythril = char_mythril + 2 where user_id = " . $user_id );
		//User::send_news( 'char', $user_id, "You got 2 mythril for your vote at " . $list_name );
	}
	mysql_query( "update voting_log set status = 'rewardgiven' where id = " . $id );
	echo '<response rewarded="1" message="Reward given." />';
}
else
{
	mysql_query( "update voting_log set status = 'rewardnotgiven' where id = " . $id );
	echo '<response rewarded="0" message="Reward not given (not unique vote)." />';
}
exit;

I hope someone will me me out how to convert this inyo mssql
this script is for voting site.
 
Joined
Mar 26, 2006
Messages
598
Reaction score
4
Mssql doesn't support the escape string function that mysql does. I would start by removing that and replacing with regular variables. I would then look into what the proper mssql syntax is for each function as well as what each one's equivalent is in mysql. There are plenty of tutorials on google about mysql with php as well as mssql in php. mysql_query = mssql_query, mysql_num_rows = mssql_num_rows.
Code:
$listname = mysql_real_escape_string( $_REQUEST['listname'] );
Would become
Code:
$listname = $_REQUEST['listname'];
That should be enough information for you to do this on your own. I also suggest reading into a couple of tutorials because something this simple isn't something you should generally ask. Not to mention if you read a couple of tutorials you won't have to sit here and post something like this again, you could do it on your own within a couple of minutes.
 

zet

Experienced Elementalist
Joined
Aug 25, 2010
Messages
251
Reaction score
24
@lordvladek
thank you the answer and tips , i will do your suggestion sorry for that i am new in this section
tip and advice would be a big help for me.

thank you :))
 
Last edited:
Back
Top