Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Reload this Page [Essentials script] PHP SQL

Notices
For all updates, view the main page.

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    
Old November 7th, 2012 (08:23 AM). Edited November 7th, 2012 by Cilerba.
Umbreon's Avatar
Umbreon Umbreon is offline
Gold Tier
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 18
Gender: Male
Nature: Calm
Posts: 1,594
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!
Reply With Quote
Reply
Quick Reply

Sponsored Links

You may also like.. (Beta)
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 -8. The time now is 12:26 PM.