How would I connect to a SQL server in unity and use it to make a log in/register. I know there are many other tutorials out there/questions, but none of these make any sense at all…
I’ve got the basic stuff such as the password/username input box. But I would like to know how to get JAVASCRIPT to connect to the sql database, look at the table and look for the username corresponding to the same one in the username box, then check to see if the password is right. If possible, I would like to also add a register part where it adds another entry to the table, checks if the activation key/username/email is not in use.
I usually use xampp for this. Simply downlaod xampp and start Apache and Mysql
Then take guide lines from this script. This is in C# but you can convert it into Javascript easily
string loginURL = "http://127.0.0.1/login.php";
IEnumerator HandleLogin()
{
label = "Checking username and password";
string login_URL = this.loginURL + "?username=" + username + "&password=" + password;
WWW loginReader = new WWW (login_URL);
yield return loginReader;
Debug.Log ( login_URL+ " loginReader="+loginReader + " error= " + loginReader.error);
if(loginReader.error != null)
{
label = "could not locate page";
Debug.Log (loginReader.error);
}else {
if(loginReader.text == "success")
{
Application.LoadLevel("second scene");
label ="logged in";
}else
{
label = "invalid user/pass";
}
}
}
In your xampp/htdocs folder paste this php script with name login.php
<?php
$user = $_GET['username'];
$pass = $_GET['password'];
$sqlconnection = mysqli_connect("localhost", "root", "", "Runner");
if(mysqli_connect_errno()) {
echo"failed to connect".mysqli_connect_error();
}
if(isset($user) && isset($pass)) {
$query = "SELECT * FROM users WHERE Username = '".$user."' and Password = '".$pass."'";
$result = mysqli_query($sqlconnection, $query);
if ($result->num_rows == 0) {
echo "Nope";
} else {
echo "success";
}
}
?>
This page explains pretty much everything regarding Unity-SQL integration.
http://wiki.unity3d.com/index.php/SQLite
SQLite Unity3d ( Android , Windows Phone , Windows , IOS, WINRT )
Connection Database Sqlite how to Create Table , Select , Insert , Update , Delete , Search:
GitHub - walidabazo/SQLiteUnity3d_Android: SQLite Unity 3d For ( Android , Windows Phone , Windows , IOS, WINRT )
Video To Create it https://www.youtube.com/watch?v=dezAuScV9ZY
**Application database Path**
string filepath = Application.dataPath + "/Plugins/" + DatabaseName;
**Application database Path android**
string filepath = Application.persistentDataPath + "/" + DatabaseName;