php - PDO搜索查询帮助! [unity3D]

标签 php unity3d pdo

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'];
            }
       }
    }
?>

数据库.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());
        }
    }
}

我一直在寻找修复的方法,但由于某种原因我找不到任何帮助,每当我在 Unity3D 上按下搜索时,它都不起作用,它甚至没有显示“成功”,尽管我在哈希正确时创建了获取数据

有人会帮助我吗? 那将不胜感激

谢谢。 最好的问候

最佳答案

您正在使用 命名占位符 :search in query()

使用 prepare() 然后绑定(bind) :searchexecute() 或通过将数据传递到 使用“惰性”绑定(bind)执行()

See PDO info 更多

关于php - PDO搜索查询帮助! [unity3D],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37870192/

相关文章:

PHP PDO : charset, 设置名称?

php - Magento - 单元测试 - 模拟对象

php - 雷迪斯 : 40+ servers reading the same redis content

javascript - 如何在不再次发送所有 APK 的情况下更新我的应用程序?

firebase - 将 Firebase 与 Unity 和 WebGL 结合使用

php - 如何用php验证选择字段?

php - Magento 中的 CSV 导入/导出问题

php - MySQL 查找连接 3 个表

android - Google Play 游戏服务 2017 : How to invite somebody to a multiplayer match?

php - sql错误: General error: 25