Big Database Problems

I can’t send simple score information to my mysql database v3.2

My SQL Table:

CREATE TABLE unitytest (
name text NOT NULL,
score text NOT NULL
) TYPE=MyISAM COMMENT=‘Highscores’;

my PHP Code/File:

<?php $host = "mysql.Server.com"; $user = "XXXXXXXXX"; $password = "XXXXXXXXX"; $base = "XXXXXXXXX"; $connexion = mysql_connect($host,$user,$password); mysql_select_db($base); $name = $_POST['name']; $score = $_POST['score']; $query = "INSERT INTO unitytest ( name, score ) VALUES ( '" . $name . "', '" . $score . "')"; mysql_close(); ?>

Unitycode:

void SendScore()
{
WWWForm form = new WWWForm();

form.AddField( “name”,“PLAYER”);
form.AddField( “score”,“30000”);

WWW connect= new WWW( scoreUrl, form);
}


What is wrong ?

  • scoreURL to php file is 100% correct
  • php File is on Server
  • MSSQL Database Name Account is 100% correct
  • Unity code runs error-free

I have programed in the past with C++ and Etna Highscores without problems. Only with Unity doesn’t work on Vista64x

$host = “mysql.Server.com”;

thats likely the problem.
The majority of webhosters do not allow any remote database accesses for security reasons.
You normally put the php on the same web server and use localhost or at least on a webserver within the same LAN and explicitely allow his IP as remote IP.

the php file is on same server like database.
And my correct sql Servername is: mysql.mydomain.com
is 100% correct. Hostet on Domaingo(Domainfactory)

ok

For specification: Not working means?
Is nothing inserted at all or are you not able to get the corresponding OK on the unity end?

I ask because the code itself is not fully complete so if you expect it to be done when the function ends, thats dangerous.

Its missing

yield connect;

Check the access logs to make sure your Unity content is properly hitting the URL. Add in a debug log that outputs to a text file and make sure the right information is making it to the PHP file. Log any MySQL errors to text file so you can see what’s not working.

Your issue is very unlikely Unity-related. We do all kinds of WWW-related calls with no issue.

I can’t use yield in C#. I have use

while(connect.isDone==false){};

… but same problem.

I have create a Form with Button. When I push the Button it should send the score.

if ( GUI.Button ( scoreButton , “Submit Score” ) )
SendScore();

The Button work fine and SendScore() will be called.

It’s a Bug in Unity in combination with Vista64x ?

I have now sent the datas without Form Array and it work fine.
I have changed the php file for this _POST to _GET and sent directly with URL …php? name=Playername&score=score using WWW(FinalURL) without form.

But sending about Form Arrays WWW(URL,form) doesn’t work. Why ?
Also when I put the strings directly.

Of course you can yield from C#. That while loop will not work though as the engine will never get a chance to service the WWW request.

The syntax for yielding from C# is different though. See: “Coroutines have a different syntax in C#.” in Writing Scripts in C# in the script reference.

I have now convert my code to Javascript.
I have tested the WWWForm with php mail() function and it works fine. But I think, the main problem is, that my database doesn’t accept data informations from _POST. No problems when I use _GET and directly send the datas in URL.

OK Problem solved.
The Problem was using yield in C#. I have now written the code in Java and now it works fine with $_POST and WWWForm. And yield is a must have function for sending the WWWForms. That I knowing now. :slight_smile:

Thanks guys!

But how can I use yield with www connection in C# ?
I have don’t understand the yield usage in c# in combination with WWW. The Manual said, I can also use www.isDone but that doesn’t work.

I’ve written an entire php handler class in C# for just this thing.

Here’s the topic:
http://forum.unity3d.com/viewtopic.php?t=18846

It has a link to my blog, which has the project to download.

It takes a little time to understand the concept of yield, and then a little more to figure out how it works with C#. The class PHPHandler specifically is for doing WWW requests with forms, to PHP / mySQL and callbacks.

hi
i have a question guys?
why you don’t use mono to connect to ODBC databases like mysql?

yild in C#
for www just do this

WWW f = new WWW(url);
yield return f;

for using things like WaitForSeconds you should do

yield return new WaitForSecond(5);

for returning normal values: yield return 0;

the function should return IEnumerator object

IEnumerator Start ()
{
WWW f = new WWW ("http://blogs.unity3d.com");
yield return f;
print ("unity's blogs page is loaded!!!");
}

Because direct access to databases is a very dangerous thing. Grab the authentication by decompiling with reflector or packet sniffing, your end user now has total control over your database.

DELETE * FROM ItemDatabase

Oops!