Connection with a MySQL Database

Hello,I’m new to Unity and I have the following problems in my JS Code :

I have the following Exception when I run my Project :

“UnityException: WWW is not ready downloading yet UnityEngine.WWW.get_text () (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/Utils.cs:87) bdd_description…ctor () (at Assets/Standard Assets/bdd_description.js:6)”

ArgumentException: InitWWW can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.WWW…ctor (System.String url) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/Utils.cs:28)
bdd_description…ctor () (at Assets/bdd_description.js:7)

Here is the code :

var afficher : boolean = false;

var res= “http://localhost/searchname.php”;

var www : WWW = new WWW (res);

yield www;

var description=www.text;

If somebody can help me it will be great !

function OnGUI() {

//style label
var bulle=new GUIStyle();
bulle.normal.textColor=Color.red;
bulle.fontSize=15;
bulle.fontStyle= FontStyle.Bold;
bulle.border.right=1;

var bulle2=new GUIStyle();
bulle2.normal.textColor=Color.red;
bulle2.fontSize=15;
bulle2.fontStyle= FontStyle.Italic;
bulle2.border.right=1;

var info= "Immeuble" ;
var e : Event = Event.current;

if (afficher == true) {
	GUI.Label (Rect (e.mousePosition.x+20, e.mousePosition.y+20, 300, 100), info, bulle );
	GUI.Label (Rect (e.mousePosition.x+40, e.mousePosition.y+40, 300, 100), description, bulle2 );
	}

}

function OnMouseOver () {
afficher = true;
}

function OnMouseExit () {
afficher = false;
}

You do exactly what the compiler tells you:

InitWWW can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

Move

var res= "http://localhost/searchname.php";
var www : WWW = new WWW (res);
yield www;
var description=www.text;

To the Awake()or Start() function.

Thank you very much it seems too work like that :

function Start() {

var res= "http://localhost/searchname.php";

var description=WWW(res).text;

yield description;
}
var afficher : boolean = false;

function OnGUI() {
		
	//style label
	var bulle=new GUIStyle();
	bulle.normal.textColor=Color.red;
	bulle.fontSize=15;
	bulle.fontStyle= FontStyle.Bold;
	bulle.border.right=1;
	
	var bulle2=new GUIStyle();
	bulle2.normal.textColor=Color.red;
	bulle2.fontSize=15;
	bulle2.fontStyle= FontStyle.Italic;
	bulle2.border.right=1;
	
	var info= "Immeuble" ;
	var e : Event = Event.current;
	
	if (afficher == true) {
		GUI.Label (Rect (e.mousePosition.x+20, e.mousePosition.y+20, 300, 100), info, bulle );
		GUI.Label (Rect (e.mousePosition.x+40, e.mousePosition.y+40, 300, 100), description, bulle2 );
		}
}

function OnMouseOver () {
afficher = true;
}

function OnMouseExit () {
afficher = false;
}

But I’ve another problem now : how to use my variable “description” (in my function Start()) in my OnGui() function?
A little help would be great !
Sorry for the newbies questions ^^