中文字幕无码a片久久,亚洲日韩在线观看浪潮,人人超人人超碰超国产二区,国产人妻久久一区二区,国产人妻久久一区二区

福感科技有限公司 歡迎您!
聯(lián)系方式

    地址:北京市平谷區(qū)馬坊鎮(zhèn)金河北街17號(hào)院3號(hào)樓7層712

    電話:010-89968230

    網(wǎng)站:http://0743119.com

Unity和PHP的Http數(shù)據(jù)交互

2021-8-31 20:10:16??????點(diǎn)擊:
大家可以經(jīng)常需要做一些簡(jiǎn)單的數(shù)據(jù)統(tǒng)計(jì),可能是使用Socket寫的服務(wù)端交互,也可能是使用http的交互。為了更契合本篇文章的主題,下面就來(lái)看下Unity是如何與PHP的Http數(shù)據(jù)交互。

PHP注冊(cè)代碼
<?php
include 'Common.php';//引用包含Check方法的php文件,這個(gè)是自己寫的,一種檢測(cè)非法手段,可以百度下,也可以不寫
$name=Check($_POST["name"]);//PHP獲取form內(nèi)容的方法,$name=$_POST["name"];
$pass=Check($_POST["pass"]);
$con=mysql_connect("127.0.0.1","root","");//連接mysql
if(!$con)
        die("Could not connect:".mysql_error());//如果連接失敗則結(jié)束
mysql_select_db("CreateData",$con);//選擇數(shù)據(jù)庫(kù)
mysql_query("set names utf8");//設(shè)置utf8,否則中文會(huì)亂碼噢
$com= mysql_query("select pass from Login where name='$name'");//查詢是否有此名稱
if(mysql_num_rows($com)!=0)
{
        die("-1");//username already exist;//如果有則結(jié)束函數(shù),并打印-1
}
mysql_query("insert into Login(name,pass,lasttime) values('$name','$pass',now())");//插入用戶名
$com=mysql_query("select uid from Login where name='$name'");
$com=mysql_fetch_array($com);
$com=$com["uid"];
echo "$com";//打印uid
mysql_close($con);//關(guān)閉數(shù)據(jù)庫(kù)
?> 
以上便是php代碼,每次訪問(wèn)都需要開關(guān)一次數(shù)據(jù)庫(kù),可以借助數(shù)據(jù)庫(kù)連接池來(lái)解決此問(wèn)題。

Unity訪問(wèn)代碼
        public void SendUserCor(string url, string name, string password)
        {
            StartCoroutine(SendUser(url, name, password));
        }
        IEnumerator SendUser(string url,string name,string password)
        {
//這個(gè)官方有對(duì)應(yīng)案例
            WWWForm from = new WWWForm();//建立表單
            from.AddField("name", name);//添加數(shù)據(jù)
            from.AddField("pass", password);
            WWW www = new WWW(url, from);//建立WWW
            yield return www;
            if (www.error != null)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log(www.text);//獲得返回的數(shù)據(jù)
                //-1 用戶名已存在
                //>0 為uid編號(hào)
            }
        }

以上便是unity和PHP的數(shù)據(jù)交互,以及PHP與mysql的交互。

聲明:文章內(nèi)容整理來(lái)源于網(wǎng)絡(luò),版權(quán)屬于原作者,如有問(wèn)題,請(qǐng)聯(lián)系我們!

來(lái)源:https://gameinstitute.qq.com/community/detail/128612

Copyright 2019 0743119.com

福感科技有限公司 版權(quán)所有 All Rights Reserved

京ICP備20002031號(hào)

010-89968230