gpt4 book ai didi

c# - 使用离线 mySQL 数据库在 Unity for android 中制作游戏

转载 作者:搜寻专家 更新时间:2023-10-30 20:50:22 24 4
gpt4 key购买 nike

<分区>

我在做一个琐事,最后有 5 个输入字段用于用户数据,例如姓名、姓氏、电话、文件编号和电子邮件。并用 mySQL 和 phpmyadmin 创建了一个数据库来存储这些数据。当我为 Windows 构建时,一切正常,但我必须为 Android 平板电脑构建,但我无法设法让数据库正常工作,如果有人能帮助我,我会很高兴!

这是我用于数据库管理的 C# 统一脚本:

using System.Collections;
using UnityEngine.UI;
using UnityEngine;

public class GestorBD : MonoBehaviour
{

public InputField txtnombre;
public InputField txtapellido;
public InputField txtci;
public InputField txttel;
public InputField txtmail;

public string nombrenombre;
public string apellidoapellido;
public int cici;
public int tel;
public string mail;

public bool sesionIniciada = false;

/// Respuestas WEB
///
/// 200 = datos encontrados
/// 201 = usuario registrado
///
/// 400 = no pudo establecer coneccion
/// 401 = no enconto datos
/// 402 = el usuario ya existe



public void IniciarSesion()
{
StartCoroutine(Login());
StartCoroutine(datos());
}
public void Registrarnombre()
{
StartCoroutine(Registrar());
}

IEnumerator Login()
{
WWW coneccion = new WWW("http://127.0.0.1/trivia/login.php?nom=" +
txtnombre.text + "&ape=" + txtapellido.text + "&ci=" + txtci.text + "&tel="
+ txttel.text + "&mai=" + txtmail);
yield return (coneccion);
if (coneccion.text == "200")
{
print("el usuario si existe");
}
else if (coneccion.text == "401")
{
print("usuario o contrasena incorrectos");
}
else
{
print("error en la coneccion con la base de datos");
}
}

IEnumerator datos()
{
WWW coneccion = new WWW("http://127.0.0.1/trivia/datos.php?nom=" +
txtnombre.text + "&ape=" + txtapellido.text + "&ci=" + txtci.text + "&tel="
+ txttel.text + "&mai=" + txtmail);
yield return (coneccion);
if (coneccion.text == "401")
{
print("usuario o contrasena incorrectos");
}
else
{
string[] nDatos = coneccion.text.Split('^');
if (nDatos.Length != 2)
{
print("error en la coneccion");
}
else
{
nombrenombre = nDatos[0];
apellidoapellido = nDatos[1];
cici = int.Parse(nDatos[2]);
tel = int.Parse(nDatos[3]);
mail = nDatos[4];
sesionIniciada = true;
}
}
}

IEnumerator Registrar()
{
WWW coneccion = new WWW("http://127.0.0.1/trivia/registro.php?nom=" +
txtnombre.text + "&ape=" + txtapellido.text + "&ci=" + txtci.text + "&tel="
+ txttel.text + "&mai=" + txtmail.text);
yield return (coneccion);
if (coneccion.text == "402")
Debug.LogError("usuario ya existe!");

else if (coneccion.text == "201")
{
nombrenombre = txtnombre.text;
apellidoapellido = txtapellido.text;
sesionIniciada = true;

}
else
{
Debug.LogError("error en la coneccion con la base de datos");
}

}


}

这是我用于登录的 php 文件:

<?php

$servidor = 'localhost';
$user = 'root';
$password = '';
$baseDatos = 'trivia';

$conexion = new mysqli($servidor, $user, $password, $baseDatos);

$nom = $_GET['nom'];
$ape = $_GET['ape'];
$ci = $_GET['ci'];
$tel = $_GET['tel'];
$mai = $_GET['mai'];

if (!$conexion)
{
echo "error";
}
else
{
$sql = "SELECT * FROM usuarios WHERE nombre LIKE '$nom' AND apellido
LIKE '$ape' AND ci LIKE '$ci' AND tel LIKE '$tel' AND mail LIKE '$mai'";
$resultado = mysqli_query($conexion, $sql);
if (mysqli_num_rows($resultado)>0)
{
echo "bien";
}
else
{

echo "mal";
}
}

?>

我的数据 php 文件:

<?php

$servidor = 'localhost';
$user = 'root';
$password = '';
$baseDatos = 'trivia';

$conexion = new mysqli($servidor, $user, $password, $baseDatos);

$nom = $_GET['nom'];

if (!$conexion)
{
echo "400";
}
else
{
$sql = "SELECT * FROM usuarios WHERE nombre LIKE '$nom'";
$resultado = mysqli_query($conexion, $sql);
if (mysqli_num_rows($resultado)>0)
{
while ($row = mysqli_fetch_assoc($resultado)){
echo

$row['nombre']."^".$row['apellido']."^".$row['ci']."^".$row['tel']
."^".$row['mail'];
}
}
else
{

echo "401";
}
}

?>

和我用于注册的 php 文件:

<?php

$servidor = 'localhost';
$user = 'root';
$password = '';
$baseDatos = 'trivia';

$conexion = new mysqli($servidor, $user, $password, $baseDatos);

$nom = $_GET['nom'];
$ape = $_GET['ape'];
$ci = $_GET['ci'];
$tel = $_GET['tel'];
$mai = $_GET['mai'];

if (!$conexion)
{
echo "400";
}
else
{
$sql = "SELECT * FROM usuarios WHERE ci LIKE '$ci'";

$resultado = mysqli_query($conexion, $sql);
if (mysqli_num_rows($resultado)>0)
{
echo "402";
}
else
{
$sql = "INSERT INTO usuarios (id, nombre, apellido, ci, tel, mail)
VALUES (NULL, '$nom', '$ape', '$ci', '$tel', '$mai')";
$resultado = mysqli_query($conexion, $sql);
echo "201";
}
}

?>

谢谢!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com