• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

PHP Moving Characters from one database to another

BarJuice

Zyloria Owner
Joined
Mar 28, 2008
Messages
118
Reaction score
1
Location
South Carolina
A little script i made last night playing around.
It isnt just one script that does it instantly, so if you dont know what your doing i wouldnt use this at all lol.

You will want to create a table in your database called player_account.

Easily made by using this
PHP:
CREATE TABLE IF NOT EXISTS `player_account` (
  `id` int(11) NOT NULL,
  `account` int(11) NOT NULL,
  `recreated` int(11) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

This first script will change all your players "ids" to a different number.
PHP:
<html><title>Zyloria Server</title>
<body>
<p><font size="5"><strong>Zyloria Server</strong></font><font size="5"><strong><br>
  <font size="2"> Conversion</font></strong></font></p>
<form name="form1" method="POST" action="allrecover.php">
  <p align="left"><em>MySQL Config.</em><br>
    <br>
    Host 
    <input name="host" type="text" id="host" value="" size="15">
    <br>
    User 
    <input name="user" type="text" id="user" value="" size="10">
    <br>
    Pass 
    <input name="pass" type="text" id="pass" value="" size="30">
    <br>
    Database 
    <input name="db" type="text" id="db" value="" size="8">
    <br>
  </p>
  <p>
    <input type="submit" value="Change!">
  </p>
  </form>

</p>
<p>&nbsp;</p><p>&nbsp;</p></body>
<p>
  <?php


$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$db = $_POST['db'];

if (!$host) {   
    echo '';   
    exit;   
} 

mysql_connect($host,$user,$pass) or die("Unable to connect with the SQL Server!");
mysql_select_db($db) or die("Unable to select the SQL Database!");

$id=1;
do
  {
	$newid = $id+1000000;
	echo "Players old ID " . $id . " changed to new ID " . $newid . " completed.<br />";
	mysql_query("UPDATE players SET id = '$newid;', rank_id = '0' WHERE id = '$id;'");
		$result = mysql_query("SELECT * FROM players WHERE id = '$newid;'");
		while($row = mysql_fetch_array($result))
  			{
			$account = $row['account_id'];
  			}
	mysql_query("INSERT INTO player_account (id, account, recreated) VALUES ('$newid;', '$account;', '0')");
	mysql_query("UPDATE players SET account_id = '1' WHERE id = '$newid;'");
	$id++;	
  }
while ($id<1379);

$id=1;
do
  {
	$newid = $id+1000000;
	echo "Player Depot Items old ID " . $playerid . " changed to new ID " . $newid . " completed.<br />";
	mysql_query("UPDATE player_depotitems SET player_id = '$newid' WHERE player_id = '$id;'");
	$id++;	
  }
while ($id<1379);

$id=1;
do
  {
	$newid = $id+1000000;
	echo "Player Items old ID " . $playerid . " changed to new ID " . $newid . " completed.<br />";
	mysql_query("UPDATE player_items SET player_id = '$newid' WHERE player_id = '$id;'");
	$id++;	
  }
while ($id<1379);

$id=1;
do
  {
	$newid = $id+1000000;
	echo "Player Skills old ID " . $playerid . " changed to new ID " . $newid . " completed.<br />";
	mysql_query("UPDATE player_skills SET player_id = '$newid' WHERE player_id = '$id;'");
	$id++;	
  }
while ($id<1379);

echo 'Database updated!';

?>

</html>
The "while ($id<1379);" does the script from 1 to 1379 player ids. If you were to be converting 10000 you would put "while ($id<10001);"
Could easily just put a variable at the top called $number and set it equal to the amount of players being moved.

The next thing you would do is run this script on the database you are getting new characters from. After you do that it is easiest to delete all other tables other than
players, player_account, player_depotitems, player_items, player_skills. You wont need those from this point on.

Export the database to a .sql file

Now go into your database you wanna import into and import that .sql file (take out every CREATE TABLE IF NOT EXISTS except for the player_account table so your just inserting into the new database)

After you import that .sql file you will want to add this page into your website. I use TFSCMS so i have the headers and footers ect already added into it to make it look good.

PHP:
<?php
include ('Includes/config_includes.php');
include ('Includes/function_includes.php');
include ('Includes/header_includes.php');
echo '
<p><font size="5"><strong>Zyloria Server</strong></font><font size="5"><strong><br>
  <font size="2"> Resetted Character Recovery Interface</font></strong></font></p>
<form name="form1" method="POST" action="recovery.php">
  <p align="left"><em>Recovery Form.</em><br>
    <br>
    Old Player Name 
    <input name="opname" type="text" id="opname" value="" size="30">
    <br>
    Old Account Number 
    <input name="oanumber" type="text" id="oanumber" value="" size="15">
    <br>
    Current Account Number 
    <input name="canumber" type="text" id="canumber" value="" size="15">
  </p>
  <p>
    <input type="submit" value="Recover!">
  </p>
  </form>

</p>
<p>&nbsp;</p><p>&nbsp;</p></body>
<p>';

$host = 'input';
$user = 'input';
$pass = 'input';
$db = 'input';
$opname = $_POST['opname'];
$oanumber = $_POST['oanumber'];
$canumber = $_POST['canumber'];

if (!$host) {   
    echo '';   
    exit;   
} 

mysql_connect($host,$user,$pass) or die("Unable to connect with the SQL Server!");
mysql_select_db($db) or die("Unable to select the SQL Database!");

$idsearch = mysql_query("SELECT * FROM players WHERE name='$opname'");
while($idsearchresult = mysql_fetch_array($idsearch))
  {
	$playerid = $idsearchresult['id'];
  }

$playersearch = mysql_query("SELECT * FROM player_account WHERE id='$playerid'");
while($playersearchresult = mysql_fetch_array($playersearch))
  {
  $player_account = $playersearchresult['account'];
  $player_recreated = $playersearchresult['recreated'];
    if ($oanumber == $player_account)
      {
	if ($player_recreated == 1)
	  {
	  echo 'This player has already been recreated. <br />';
	  }
	else
	  {
	  echo 'Your player has been added back to your account. <br />';
	  mysql_query("UPDATE player_account SET recreated = '1' WHERE id = '$playerid;'");
	  mysql_query("UPDATE players SET account_id = '$canumber' WHERE id = '$playerid;'");	
	  }
	}
    else
      {
	echo 'The old account number you supplied is incorrect. <br />';
	}
  }
include ('Includes/footer_includes.php');
?>

Im not a pro .php creater but this works for me, I wouldnt mind any tips on how to make this script a little more "User Friendly". I'd also like some critism on any weaknesses it would have.
 
It is useless

I agree, if you have no purpose to use it.
But it wasnt useless for me.
So i decided to release it to the public so maybe it wouldnt be useless for someone else :p
 
It's doing well for me.
Thanks, btw you're name is pretty long. Haha! (a)
 
It's nice script, some people would need it, good job tho.
 
Great, I really need this.. though I'm too tired atm to try it out so I'll probably fail XD

might test it out tomorrow if I find out there aren't any other way to keep ur chars, oh and btw the acc gets transfered aswell right? :D
 
Back
Top