- Home /
insert values into mySQL databases
I would like to insert data into mySQL. How can i go about doing this?? I have read up all about php/WWW form but i find it hard to do one. Any kind soul willing to providing some sample code snippet??
what you mean by where is mySQL database located? It is located in the same project as the games. I created a folder name plugins to store all the dlls that is needed for mySQL.. I am creating a standalone games.
Are you talking about $$anonymous$$ySQL or SQLite? You can't have $$anonymous$$ySQL packed with your game.
Sorry i am confused. I am using mySQL. I am using mySQL workbench to edit, create all database instance. :) ACtually initially i am using sqlite, but when i run using .exe file, it doesn't update my database at all. thatwise change to mySQL
Answer by dkNinja · Apr 13, 2012 at 04:26 AM
I have used MySQL and SQLite with Unity3d. From my experience, I would highly suggest using SQLite unless you have a feature in MySQL that isn't available in SQLite. That said, in order to have SQLite working in an .exe file, you have to include sqlite3.dll file in the plugins directory during build time. You can download the dll for your system on the SQLite website.
If you still want to use MySQL, you can follow the tutorial at http://www.freewebmasterhelp.com/tutorials/phpmysql
Answer by Thewhiteaura · Jun 01, 2015 at 09:05 PM
sorry to post to an old question, but to anybody coming across this, and to the original poster as well (should they re-read this), before you indulge in that website (may be good for general knowledge) I highly recommend reading through this article as well if you are going to be using MySQL.
http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
and another site for PDO
Answer by ash_05 · Apr 02, 2016 at 05:27 AM
first create a database and create a php code(register.php) and place it in you wamp
<?php
$username=$_REQUEST['username'];
$password=$_REQUEST['password'];
$database = mysql_connect('localhost', 'root', 'amma') or die('Failed to connect: ' . mysql_error());
mysql_select_db('gameuser') or die('Failed to access database');
$query="INSERT INTO users(username,password) VALUES('$username','$password');";
$result=mysql_query($query);
echo "registered";
?>
unity code
string getscoreCode="http://192.168.173.243/GameDatabase/register.php";
public Rect windowRect0 = new Rect(20,20,500,300);
public Rect windowRect1 = new Rect(20,350,500,0);
public Rect windowRect2 = new Rect(20,450,500,0);
public static string username="";
public static string password="";
public static string result="";
public string scoreboard="";
public string highscore="";
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI() {
windowRect0 = GUI.Window(0, windowRect0, LeaderBoard, "SCORE ENTRY BOARD");
if(GUI.Button (new Rect (400, 450, 150, 50), "add"))
{
Application.LoadLevel("ScoreBoardDisplay");
}
}
void LeaderBoard(int windowID) {
GUI.Label (new Rect (140, 40, 150, 100), "Enter the Players name");
username = GUI.TextField (new Rect (25, 60, 375, 30), username);
GUI.Label (new Rect (140, 92, 150, 100), "Enter the password");
password= GUI.TextField(new Rect (25, 115, 375, 30), password);
if (GUI.Button (new Rect (150, 160, 175, 50), "Save the Score"))
StartCoroutine(handleEnterScore(username,password));//
GUI.Label (new Rect (55, 222, 250, 100),result);
}
IEnumerator handleEnterScore(string user,string pass)
{
string register_url = getscoreCode + "?username=" + user + "&password=" + pass;
WWW entereddata = new WWW (register_url);
yield return entereddata;
if(entereddata.text == "registered")
{
result=" correctly";
}
else{
result="incorrectly";
}
username = "";
password= "";
}
}
Your answer
