x


Can we access my sql database using network concept?

Hi,

          Is it possible to connect the local sql database to Network?
more ▼

asked Jul 24 '12 at 12:57 PM

schetty gravatar image

schetty
16 2 7 13

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Change your localhost to your global DNS

script.js

var addScoreUrl = "http://localhost/connecttosql.php?";//the ? mark is for the query
function PostScore(name:String, score:int){

var hash = Md5.Md5Sum(name + score + secretKey);

var highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "≻ore=" + score + "&hash=" + hash;

hs_post = WWW(highscore_url);//send url yield hs_post;// wait untill something back

if(hs_post.error){ print("Error posting score: " + hs_post.error); } Application.LoadLevel("HighScore"); }

connecttosql.php

<?php 
    $db = mysql_connect('localhost', 'root', '') or die('Could not connect: ' . mysql_error()); 
    mysql_select_db('mydb') or die('Could not select database');

    // Strings must be escaped to prevent SQL injection attack. 
    $name = mysql_real_escape_string($_GET['name'], $db); 
    $score = mysql_real_escape_string($_GET['score'], $db); 
    $hash = $_GET['hash']; 

    $secretKey="777"; # Change this value to match the value stored in the client javascript below 

    $real_hash = md5($name . $score . $secretKey); 
    if($real_hash == $hash) { 
        // Send variables for the MySQL database class. 
        $query = "insert into scores values (NULL, '$name', '$score');"; 
        $result = mysql_query($query) or die('Query failed: ' . mysql_error()); 
    } 

?>

more ▼

answered Jul 26 '12 at 09:39 AM

utoyo gravatar image

utoyo
3 2

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5076
x709
x701

asked: Jul 24 '12 at 12:57 PM

Seen: 355 times

Last Updated: Jul 26 '12 at 09:39 AM