Using WWW to get data from sql database

I have been working in unity for a little while now and I was fiddling about in Unity 2.6 Indie Free version at home.

I have the following script and php file:

PHPFunctions.js

#pragma strict

var gameGui : GameGui;
var nextHexSpawn : float = 0;
var hexCount : float = 0;

function getHexCount() : System.Collections.IEnumerable
{
	var url : String = "http://www.online-behemoth.com/behemoth/gethexcount.php";
	var countGet : WWW = new WWW(url);
	
	yield countGet;
	
	if(countGet.error)
	{
		gameGui.addErrorMessage(countGet.error);
	}
	else
	{
		hexCount = parseFloat(countGet.data);
		Debug.Log(countGet.data);
	}
}

header.php

<?php	
	/* Get config */
	include ('config.php');

	/* Connect to database */
	require('databaseconnect.php');

?>

gethexcount.php

<?php
	include('header.php');


	$result = mysql_query("SELECT * FROM behemoth_hex");
	echo mysql_num_rows($result);
?>

http://www.online-behemoth.com/behemoth/gethexcount.php

All I get is a Debug.Log output of 0. The result should be 7 however and works fine through firefox.

Is there something going wrong here or is it an issue with me using Indie 2.6 Free version? Is this a Pro-only feature?

You should let Unity automatically determine the return type of your function, instead of explicitly declaring it.

In this case you used System.Collections.IEnumerable instead of System.Collections.IEnumerator, which is causing your trouble.

I just did what the editor told me too with the pragma strict. I see where I went wrong however. The editor said to make it of the type System.Collections.IEnumerable and to do that I need to make it of the type System.Collections.IEnumerator. :slight_smile:

Thank you heaps, your change works fine. :slight_smile: