tags:

views:

28

answers:

0

When game.load is called and then game.addHit is called the ruby page stops loading at all yet if I don't call add Hit it doesn't and if I rename game.load to game.loadGame that doesn't load either.

#!/usr/bin/ruby

require 'rubygems'
require 'mysql'

class Game
  attr_accessor :id, :name, :urlName, :description, :hits, :categorys, :width, :height, :nilGame

  def fillStr(id, name, urlName, description, hits, categorys, width, height)
    @id = id
    @name = name
    @urlName = urlName
    @description = description
    @hits = hits
    @categorys = categorys
    @width = width
    @height = height
  end

  def fillHash(hash)
    @id = hash['id']
    @name = hash['name']
    @urlName = hash['urlname']
    @description = hash['description']
    @hits = hash['hits']
    @categorys = hash['categorys']
    @width = hash['width']
    @height = hash['height']
  end

  def addHit
    begin
      con = Mysql.new('localhost', 'user', 'pass', 'database')
    rescue Mysql::Error => e
      puts "mysql error"
      con.close if con
    end
    @hits = Integer(@hits) + 1
    con.query("UPDATE games SET 'hits' = '#{@hits}' WHERE id = '#{@id}'")
    con.close
  end

  def load(id)
    begin
        con = Mysql.new('localhost', 'user', 'pass', 'database')
    rescue Mysql::Error => e
        puts "mysql error"
        con.close if con
    end

    rs = con.query("select * from games where id='#{id}' limit 1")
    rs.each_hash do |row|
      if row['id'].nil?
        @nilGame = true
      else
        @id = id
        @name = row['name']
        @urlName = row['urlname']
        @description = row['description']
        @hits = row['hits']
        @categorys = row['categorys']
        @width = row['width']
        @height = row['height']
      end
    end
    con.close
  end

end