Jump to content
Sign in to follow this  
Babylon

PHP Script to update your DBs.

Recommended Posts

<?php

$mysql_host = "localhost"; #Hostname / IP
$mysql_database = "world"; #Database
$mysql_user = "root"; #Mysql username
$mysql_password = "trinity"; #Mysql password

#For each begin
foreach(glob('world/*.sql') as $file) {
#Connect to DB
$db = new PDO("mysql:host=$mysql_host;dbname=$mysql_database", $mysql_user, $mysql_password);
#Get the file in question
$query = file_get_contents($file);
#Prepare
$stmt = $db->prepare($query);
#Execute
if ($stmt->execute()) {
     echo $file." Success<br />";
   }
else {
     echo $file." Fail<br />";
   }
}

This script needs to be on a webserver.

Go to the directory containing the PHP file. Create a new folder called "world", transfer all your database update files in there. (C:\TrinityCore\sql\updates\world\3.3.5)

 

It will produce a list:

world/2018_02_19_00_world.sql Success
world/2018_02_19_01_world_335.sql Success
world/2018_02_19_02_world_335.sql Success
world/2018_02_19_03_world_335.sql Success
world/2018_02_19_04_world_335.sql Success
world/2018_02_19_05_world_335.sql Success
world/2018_02_19_06_world_335.sql Success
world/2018_02_19_07_world_335.sql Success
world/2018_02_19_08_world_335.sql Success
world/2018_02_19_09_world_335.sql Success
world/2018_02_19_10_world_335.sql Success
world/2018_02_19_11_world_335.sql Success
world/2018_02_19_12_world_335.sql Success
world/2018_02_19_13_world_335.sql Success
world/2018_02_19_14_world_335.sql Success
world/2018_02_19_15_world_335.sql Success
world/2018_02_19_16_world_335.sql Success
world/2018_02_19_17_world_335.sql Success
world/2018_02_19_18_world_335.sql Success
world/2018_02_21_00_world_335.sql Success
world/2018_02_21_01_world.sql Fail

 

Can also be used for other things, than just updating your world db.

*IF USING FUSIONCMS IT MAY INTERFERE WITH ITS HTACCESS.

**MAKE SURE TO PLACE THE PHP / WORLD DIRECTORY IN A WHILELISTED FOLDER.

 

- Thought to share this in case anyone else need it. Takes too long to manually do this. If there's other methods to doing this, please share them in the comments or in your own thread. :)

Share this post


Link to post
Share on other sites

That is very very nvm EXTREMELY insecure to use in a public website. You must check the contents of the file and split and prepare the queries before execution. what if in one of the files I have a query, TRUNCATE TABLE `whatever`; or DROP DATABASE; ? 

Share this post


Link to post
Share on other sites
On 1/20/2019 at 9:43 PM, darksoke said:

That is very very nvm EXTREMELY insecure to use in a public website. You must check the contents of the file and split and prepare the queries before execution. what if in one of the files I have a query, TRUNCATE TABLE `whatever`; or DROP DATABASE; ? 

I wouldn't recommend using it on anything that's got an outside connection, but it's surely a good script, instead of using a program / tool, this is way easier to set up for some people.

 

If you have such an SQL file, it's too bad, it will execute it, can't do anything about it, but as i said in the main post, use the updates that comes along with the world table when compiling your TrinityCore. It's an easier way to execute all of the files, in one single go.

 

- Sorry for late reply, didn't see you commenting. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...