# Big Database Problems

**URL:** https://discussions.unity.com/t/big-database-problems/390589
**Category:** News & General Discussion
**Created:** [April 20, 2009, 1:36am UTC](https://discussions.unity.com/t/big-database-problems/390589 "2009-04-20T01:36:27Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Gaspedal](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Gaspedal](https://discussions.unity.com/u/Gaspedal)
#### Post date: [April 20, 2009, 1:36am UTC](https://discussions.unity.com/t/big-database-problems/390589/1 "2009-04-20T01:36:27Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [April 20, 2009, 1:38am UTC](https://discussions.unity.com/t/big-database-problems/390589/2 "2009-04-20T01:38:19Z")

</div>

$host = “[mysql.Server.com](http://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.

---

<div class="post-metadata">

### Author: ![Gaspedal](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Gaspedal](https://discussions.unity.com/u/Gaspedal)
#### Post date: [April 20, 2009, 1:44am UTC](https://discussions.unity.com/t/big-database-problems/390589/3 "2009-04-20T01:44:48Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Dreamora](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/dreamora/32/91058_2.png) [@Dreamora](https://discussions.unity.com/u/Dreamora)
#### Post date: [April 20, 2009, 2:12am UTC](https://discussions.unity.com/t/big-database-problems/390589/4 "2009-04-20T02:12:40Z")

</div>

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;

---

<div class="post-metadata">

### Author: ![MatthewW](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/mattheww/32/523829_2.png) [@MatthewW](https://discussions.unity.com/u/MatthewW)
#### Post date: [April 20, 2009, 2:49am UTC](https://discussions.unity.com/t/big-database-problems/390589/5 "2009-04-20T02:49:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Gaspedal](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Gaspedal](https://discussions.unity.com/u/Gaspedal)
#### Post date: [April 20, 2009, 10:08am UTC](https://discussions.unity.com/t/big-database-problems/390589/6 "2009-04-20T10:08:10Z")

</div>

> [@""](#):
>
> 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;

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.

---

<div class="post-metadata">

### Author: ![Gaspedal](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Gaspedal](https://discussions.unity.com/u/Gaspedal)
#### Post date: [April 20, 2009, 12:22pm UTC](https://discussions.unity.com/t/big-database-problems/390589/7 "2009-04-20T12:22:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![anon\_85789830](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@anon\_85789830](https://discussions.unity.com/u/anon_85789830)
#### Post date: [April 20, 2009, 1:35pm UTC](https://discussions.unity.com/t/big-database-problems/390589/8 "2009-04-20T13:35:19Z")

</div>

> [@""](#):
>
> I can’t use yield in C#. I have use
> 
> while(connect.isDone==false){};
> 
> … but same problem.

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#](http://unity3d.com/support/documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html) in the script reference.

---

<div class="post-metadata">

### Author: ![Gaspedal](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Gaspedal](https://discussions.unity.com/u/Gaspedal)
#### Post date: [April 20, 2009, 3:30pm UTC](https://discussions.unity.com/t/big-database-problems/390589/9 "2009-04-20T15:30:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Gaspedal](https://avatars.discourse-cdn.com/v4/letter/g/13edae/32.png) [@Gaspedal](https://discussions.unity.com/u/Gaspedal)
#### Post date: [April 20, 2009, 4:36pm UTC](https://discussions.unity.com/t/big-database-problems/390589/10 "2009-04-20T16:36:06Z")

</div>

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. 🙂

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.

---

<div class="post-metadata">

### Author: ![anon\_49100522](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@anon\_49100522](https://discussions.unity.com/u/anon_49100522)
#### Post date: [April 27, 2009, 11:46am UTC](https://discussions.unity.com/t/big-database-problems/390589/11 "2009-04-27T11:46:51Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![Ashkan\_gc](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Ashkan\_gc](https://discussions.unity.com/u/Ashkan_gc)
#### Post date: [September 3, 2009, 2:16pm UTC](https://discussions.unity.com/t/big-database-problems/390589/12 "2009-09-03T14:16:23Z")

</div>

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

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

```

for using things like WaitForSeconds you should do

```auto
yield return new WaitForSecond(5);

```

for returning normal values: yield return 0;

the function should return IEnumerator object

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

```

---

<div class="post-metadata">

### Author: ![Quietus2](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/quietus2/32/444325_2.png) [@Quietus2](https://discussions.unity.com/u/Quietus2)
#### Post date: [September 3, 2009, 3:56pm UTC](https://discussions.unity.com/t/big-database-problems/390589/13 "2009-09-03T15:56:23Z")

</div>

> [@""](#):
>
> hi  
> i have a question guys?  
> why you don’t use mono to connect to ODBC databases like mysql?

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.

```auto
DELETE * FROM ItemDatabase

```

Oops!
