The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Resources > Scripts & Tutorials
Register New Account FAQ/Rules Chat 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.



Reply
Thread Tools
  #1  
Unread November 7th, 2012, 04:23 PM
hansiec's Avatar
hansiec
Scripting Genius
 
Join Date: Aug 2009
Location: Somewhere on earth where else?
Age: 16
Gender: Male
Nature: Adamant
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!
__________________
My Game:



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

Sponsored Links


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

Forum Jump


All times are UTC. The time now is 08:06 AM.


Style by Perdition Haze, artwork by Sa-Dui.
Like our Facebook Page Follow us on TwitterMessage Board Statistics | © 2002 - 2013 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to Pokémon USA, Inc. and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company, Pokémon USA, Inc., The Pokémon Company International, or Wizards of the Coast. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2013 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 posts belong to the user.