Help - Search - Members - Calendar
Full Version: Automated Sql Script Reader
SphereServer Forums > Sphere .56/.57 > FUNCTION & EVENTS Script Submissions
Admin Ankron
If you have an SQL file that you need to have automated, this is how you do it Save the code included at the end of this post in it's own SCP file, then create a folder named "SQL" in your sphereserver dirrectory. Put an sql file in the new folder you just named "SQL" (example below). Make sure that you have the filecommands option set in your sphere ini. Finally in game, on the console, or in a script, type "run_sql mysqlfile.sql".

CODE

create table demo (
    id int unsigned not null auto_increment primary key,
    account varchar(15),
    name varchar(15),
    guild text,
    kills int,
    fame int,
    karma int);

INSERT INTO demo(id, account, guild, kills, fame, karma)
VALUES(NULL,
    'test',
    'test',
    0,
    20000,
    20000);

CODE

[function run_sql]
if (<FILE.FILEEXIST SQL\<args>>)
    local.file=<FILE.OPEN SQL\<args>>
    for i 1 <FILE.FILELINES SQL\<args>>
        if (strmatch(<local.sql>, 0))
            local.sql=<FILE.READLINE <eval <local.i>>>
        else
            local.sql=<local.sql><FILE.READLINE <eval <local.i>>>
        endif
    endfor
    FILE.CLOSE <args>
endif
DB.CONNECT
DB.execute(<local.sql>);
DB.CLOSE
Fire-Dragon-DoL
nice...however normal people who have a database server have also apache/a console where they can do the same exact thing...
Admin Ankron
QUOTE(Fire-Dragon-DoL @ 13 Dec 2007, 10:58 AM) [snapback]205689[/snapback]

nice...however normal people who have a database server have also apache/a console where they can do the same exact thing...


Very true, but I wanted to make it so that those who wish could use this script in they're scripting methods... For example, I'm working on an auction system, and I need it to create the sql table automatically when the script is run, with out a whole lot of SQL cluttering up the linked list in sphere, or my programing. Also helps with SQL systems that are intended to only be accessed in game, IE auction, chat, housing systems. In fact there are probably quite a few people who don't know much about this stuff and may have picked up a server package... thats what I did the first time I wanted to play with php.

It's just simply to make in game automation a little easier.
nazghul-ll
Hum - you still need a file with well formed SQL commands. So you could just do

mysql -u username -p password databasename <name_of_file.sql

Or, if you really want to start it as a command from sphere, just let sphere execute the above as system commend
Admin Ankron
QUOTE(nazghul-ll @ 13 Dec 2007, 08:38 PM) [snapback]205703[/snapback]

Hum - you still need a file with well formed SQL commands. So you could just do

mysql -u username -p password databasename <name_of_file.sql

Or, if you really want to start it as a command from sphere, just let sphere execute the above as system commend


Thanks, but I'm not sure if that would actually work from a script.
Maximus
On a different note, nice script smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.