The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.


Advertise here

Reply
 
Thread Tools
  #1    
Old November 7th, 2012, 08:23 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm

Advertise here
Dang, I was meaning to release this on monday...
Anyways it's an easy way to use MySQL.

Code:
=begin
   * PHP SQL
   
   * By Hansiec
   
   * Allows connection to mysql via PHP
   
   * Example:
     $sql = MySql.new("php script url")
     sql=$sql.query("SELECT * FROM `$base`.`table`")
     print $sql.get_data(sql, "test", $sql.size(sql, "test")-1)
     
   * The following example will print out the last index of test from the given
     query.
     
   * Yes I do know this breaks from traditional sql connections but in this case
     it is slightly more easier to handle : D
     
   * Features:
     ~ Allows you to connect to databases without any difficulty at all
     ~ Easily retrieve data from your queries by using the get_data function
     ~ No Harm done when your RGSSAD is cracked (see the warning concerning this)
     
   * Warnings:
     ~ If your game is cracked, your database is as good as cracked even though
       they don't have the password (as they can still query using the url)
       although there are a few simple tricks to stop those who cannot script
       from by passing this.
    
   * Tricks:
     You can also do a VERY simple checks against hacks in a few ways:
     ~ Below the comment end line put this: exit if $DEBUG
       This will prevent the game from loading in debug mode.
     ~ in the function initialize (below the line: @database = d) put down:
       @database = "" if $DEBUG
       This will prevent the url from being used.
     ~ same as the first trick except replace the if $DEBUG with:
       if !FileTest.exist?("Game.rgssad")
       This will prevent the game from being loaded if there is no rgssad.
       
     NOTE: This is a very small amount of methods you can use to check against
           Hacks but in the end with a small amount of scripting can be hacked
           though.
           
     NOTE: The namespaces to use in get_data and get_size are column names.
     
     NOTE: Credits ARE REQUIRED!!
     
     BEFORE REPORTING BUGS MAKE SURE TO GET THE ERROR REPORT!
     THE PHP FILE SHOULD ALSO PRODUCE ERRORS IN IT'S RETURN, BE SURE TO GET THAT
     TOO!
=end

$base = "pokemon" # database name
SQL_ENABLED = true # don't remove/change this, it allows other external sql scripts
# of mine to connect with the sql.
class MySql
  
  attr_accessor :database
  
  # initializes the database
  def initialize(d)
    @database = d;
  end
  
  # creates a mysql query (Untested)
  def query(query)
    if query.include?("$base")
      tmp = query.split("$base")
      query = ""
      for j in 0..tmp.length-2
        i=tmp[j]
        query += i+$base
      end
      query+=tmp[tmp.length-1]
    end
    return pbPostData(@database, {"query"=>query})
  end
  
  # returns the data from a namespacing and it's index id (Fully Tested)
  def get_data(data, name, index)
    dat=data.split(";"+name+"#{index}=")[1]
    return false if dat == nil
    return dat.split(";")[0].to_i if dat.split(";")[0].to_i.to_s == dat.split(";")[0]
    return dat.split(";")[0]
  end
  
  # returns this size of a namespace (Fully Tested)
  def get_size(data, name)
    return 0 if !data.include?(name+"0") # return if name0 doesn't exist which
    # makes it useless to process everything.
    amt = data.count(";")
    size=data.count(";"+name)/(name.length)
    while !data.include?(";"+name+"#{size}")
      size -= 1
    end
    return size+1
  end
  
end

also you must download this too: PHP_SQL.zip

IF YOU DON'T KNOW WHAT A PHP FILE IS OR HOW TO USE A PHP FILE DON'T USE IT!

Last edited by Cilerba; November 7th, 2012 at 03:29 PM.
Reply With Quote
Reply
Quick Reply

Sponsored Links


Advertise here
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 10:33 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.