[英]How to connect Unity Mobile App to Azure SQL Database?
im developing an app in Unity for Android and iOS. 我在Android和iOS版Unity中开发了一个应用。
The app will prompt the user to fill out a survey on the first use, I need the data from that survey to be stored in a database for analytics and I decided it would be Azure. 该应用程序将提示用户首次使用时填写调查,我需要将该调查中的数据存储在数据库中进行分析,然后我决定将其设为Azure。
What Azure services will I need to implement this functionality? 要实现此功能,我需要哪些Azure服务? I need it to be as little and economical as possible as they are the only data I will store and the app is small. 我需要它尽可能的少和经济,因为它们是我将要存储的唯一数据并且应用程序很小。
And from the Azure services needed, how do you implement that functionality? 从所需的Azure服务中,如何实现该功能? Any tutorials for beginners? 有适合初学者的教程吗?
I also have basic knowledge of Azure. 我也有Azure的基础知识。
Thank you very much! 非常感谢你! I hope you can help me. 我希望你能帮助我。
You will need to use a POST method. 您将需要使用POST方法。
Create a PHP file to connect to your database and then use your code to send the data. 创建一个PHP文件以连接到数据库,然后使用您的代码发送数据。
example C#: 示例C#:
public void CreateUser(string username, string firstName, string lastName, string email, string phoneNumber)
{
WWWForm form = new WWWForm();
form.AddField("userNamePost", username);
form.AddField("firstNamePost", firstName);
form.AddField("lastNamePost", lastName);
form.AddField("phoneNumberPost", phoneNumber);
form.AddField("emailPost", email);
WWW www = new WWW("URL of the PHP file", form);
}
example PHP: 示例PHP:
<?php
$servername = "localhost";
$server_username = "root";
$server_password = "";
$dbName = "databaseName";
$userName = $_POST['userNamePost'];
$firstName = $_POST['firstNamePost'];
$lastName = $_POST['lastNamePost'];
$phoneNumber = $_POST['phoneNumberPost'];
$emailAddress = $_POST['emailPost'];
$conn = new mysqli($servername, $server_username, $server_password, $dbName);
if(!$conn)
{
die("Connection Failed" .mysqli_connect_error());
}
else
{
echo "Connected";
}
$sql = "INSERT INTO table (all field names) VALUES ('".$userName."','".$firstName."','".$lastName."','".$phoneNumber."','".$emailAddress."')";
$result = mysqli_query($conn, $sql);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.