PDO搜索查询帮助! [unity3D]

PHP dispdb.php

<?php
    // Configuration
    $hostname = '1(Ignore this)';
    $username = '1(Ignore this)';
    $password = '1(Ignore this)';
    $database = '1(Ignore this)';

    $secretKey = "1(Ignore this)";

    try {
        $dbh = new PDO('mysql:host='. $hostname .';dbname='. $database, $username, $password);
    } catch(PDOException $e) {
        echo '<h1>An error has occurred.</h1><pre>', $e->getMessage() ,'</pre>';
    }

    $realHash = md5($_GET['search'] . $secretKey); 

    if($realHash == $hash){
       $sth = $dbh->query('SELECT * FROM `oidevstool` WHERE `id` =:search ORDER BY `id`');
       $sth->setFetchMode(PDO::FETCH_ASSOC);

       $result = $sth->fetchAll();

       if(count($result) > 0) {
           foreach($result as $r) {
               echo $r['id'] . "/" . $r['title'] . "/" . $r['priority'] . "/" . $r['deadline'] . "/" . $r['comment'];
            }
       }
    }
?>

database.cs

using UnityEngine;
using System.Collections;

public class database : MonoBehaviour {
    private string secretKey = "1(Don't mid this)"; // Edit this value and make sure it's the same as the one stored on the server
    public string addScoreURL = "1(Don't mid this)"; //be sure to add a ? to your url
    public string highscoreURL = "http://example.com/dispdb.php?";
    public string dataRetrieved;
    public string search;

    public string Md5Sum(string strToEncrypt)
    {
        System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
        byte[] bytes = ue.GetBytes(strToEncrypt);

        // encrypt bytes
        System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] hashBytes = md5.ComputeHash(bytes);

        // Convert the encrypted bytes back to a string (base 16)
        string hashString = "";

        for (int i = 0; i < hashBytes.Length; i++)
        {
            hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
        }

        return hashString.PadLeft(32, '0');
    }

    // Get the scores from the MySQL DB to display in a GUIText.
    // remember to use StartCoroutine when calling this function!
    IEnumerator GetScores()
    {
        string hash = Md5Sum(search + secretKey);

        string post_url = highscoreURL + "search=" + search + "&hash=" + hash;

        WWW hs_post = new WWW(post_url);
        WWW hs_get = new WWW(highscoreURL);
        yield return hs_get;

        if (hs_get.error != null)
        {
            print("There was an error getting the high score: " + hs_get.error);
        }
        else
        {
            dataRetrieved = hs_get.text;    
        }
    }

    void OnGUI()
    {
        GUI.Box(new Rect(0, 0, 800, 800), dataRetrieved);
        search = GUI.TextField(new Rect(805, 0, 200, 30), search);

        if(GUI.Button(new Rect(805, 35, 200, 30), "Search"))
        {
            StartCoroutine(GetScores());
        }
    }
}

i've looking ways to fix but i couldn't find any help for some reason this doesn't work whenever i pressed searched on Unity3D it didn't even show the "success", eventhough i made when hash are correct get data

any chance of someone going to help me? that't will be very appreciated

Thankyou. Best Regards

duanfenhui5511
duanfenhui5511 哦,是的我修复了查询行,但仍然无法使其工作
大约 4 年之前 回复
doulv1760
doulv1760 我从未见过像这样使用的WHERE子句。你确定它不应该是oidevstool.id?
大约 4 年之前 回复
dsaf32131
dsaf32131 id和oidevstool之间有一个空格
大约 4 年之前 回复
dongyu4455
dongyu4455 您的查询中是否应该有空格oidevstoolID?
大约 4 年之前 回复

2个回答



您正在使用命名占位符</ code>:在 query()</ code>中搜索。< / p>

使用 prepare()</ code>然后绑定:search </ code>和 execute()</ code>或使用“lazy”绑定 通过将数据传递到 execute()</ code>。</ p>

请参阅 PDO信息</ strong> 了解更多信息</ p>
</ div>

展开原文

原文

You are using a named placeholder :search in query() .

Use prepare() then either bind :search and execute() or use "lazy" binding by passing data into execute().

See PDO info for more



if($ realHash = $ hash){</ code>应为 if($ realHash === $ hash){</ code> </ p>
</ div>

展开原文

原文

if($realHash = $hash){ should be if($realHash === $hash){

donglaoe2979
donglaoe2979 仍然无法正常工作
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问