Search Unity

Mysql/high scores ?!?!?! help!

Discussion in 'Scripting' started by half_voxel, Apr 29, 2008.

  1. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Hi.
    I have been looking for an example to show me how i can store high scores on the web. So far the only thing i have seen is the high score tutorial for Mysql. But i have no idea of how to instal Mysql and use it, I tried downloading the community mysql server but it didn't seam to instal anything. (I need this to be able to run as standalone too). Is there another way of doing this?

    Please help!!!
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Easiest way is XAMPP from apachefriends.org
    Will install Apache (needed for the PHP backend to communicate with) and MySQL
     
  3. mjjw

    mjjw

    Joined:
    Nov 12, 2005
    Posts:
    59
    or MAMP (just google for it).

    MAMP installs Apache, MySQL and PHP into a self-cotained MacOSX application that runs like any other application. Not the best for actual deployment of websites, but great for development.
     
  4. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Thank you very much! MAMP was just the thing i was looking for.
    There is only one thing i don't understand, how do i upload the databases to a server? But i guess i can look it up in the docs somewhere.
     
  5. mjjw

    mjjw

    Joined:
    Nov 12, 2005
    Posts:
    59
    You need to export your database to an SQL file then run that SQL on the remote version on MySQL.

    The easiest way to do this is to use phpMyAdmin (which comes pre-installed with MAMP and also with a lot of PHP web hosts)
     
  6. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    Ok. So, now i have exported my DB to a .sql file and placed it on my server so now i can just have this code to connect to it?:

    Code (csharp):
    1.  
    2. <?php
    3.     // Send variables for the MySQL database class.
    4.     $database = mysql_connect('http://arongranberg.com/mysql/', 'root', 'root') or die('Could not connect: ' . mysql_error());
    5.     mysql_select_db('Marble_scores.sql') or die('Could not select database');
    6. ...
    7. ...
    8.  
    Marble_scores.sql is the DB
    http://arongranberg.com/mysql/ is the folder in witch the DB is stored
     
  7. mjjw

    mjjw

    Joined:
    Nov 12, 2005
    Posts:
    59
    Ummm. No.

    What you need to do is use phpMyAdmin, or a similar database tool on your webserver to 'run' the SQL contained in your .sql file on the MySQL server program that runs on your webserver. If you have phpMyAdmin available on your website then use that.

    When you create the database on your remote server you will give it a name, such as "HighScores" this is then the name you use with mysql_select_db.

    In your PHP script below you have put a http:// address into the parameter where your server should go. The name of your MySQL server is usually localhost (which means that the MySQL server is the same machine as your webserver is running on). However some web hosts have different values.
     
  8. half_voxel

    half_voxel

    Joined:
    Oct 20, 2007
    Posts:
    978
    YES, now i finally got it to work!!
    I had to do some tweaking with the code but now it's working perfectly!!

    Thanks to you who have helped me :D

    ---
    The forum RULES!!