我尝试了几种不同的方法,在函数get_dollars中将$ dollar从object转换为string,但没有成功。这就是var_dump所说的:
dollars: object(stdClass)#4 (1) {
["dollars"]=>
string(2) "10"
}
UnityEngine.Debug:Log(Object)
<GetDollars>c__Iterator2C:MoveNext() (at Assets/MultiOnline/UMA/Example/Scripts/UMACharacterCustomization.cs:249)
这是代码:
UMACharacterCustomization.class.php
<?php
//MOPlayer: manage all interactions with the player_name MySQL table
Class UMACharacterCustomization extends MODb{
//character name
private $name;
private $errorMessage=null;
private $dollarMessage;
private $euroMessage=null;
private $dollars=null;
private $euros=null;
// Constructor
function __construct($user, $pass, $host, $dbName){
parent::__construct($user, $pass, $host, $dbName);
}
// Destructor
function __destruct(){
parent::__destruct();
}
// Getter
public function __get($nom){
if(isset($this->$nom)){
return $this->$nom;
}
}
//Save the player_name
public function playername($name,$user_name){
if(!empty($name)&&!empty($user_name)){
$this->name->$name;
$this->user_name->$user_name;
$array = array(
':player_id' => '',
':player_name' => secure_prepare_db($name),
':userName' => secure_prepare_db($user_name)
);
// $array=array(':player_id' => '',
//':player_name' => secure_prepare_db($this->$name));
$this->prepare_exec('INSERT INTO players(player_id,player_name,userName) VALUES(:player_id,:player_name,:userName)', $array);
}else{
$this->errorMessage.= $name;
}
return false;
}
public function get_dollars($user_name){
if(!empty($user_name)){
$this->user_name->$user_name;
$array=array(':userName' => secure_prepare_db($user_name));
$dollars = $this->query_fetchObject('SELECT dollars FROM
players WHERE userName=\''.$user_name.'\'');
$this->dollarMessage.= (string)$dollars ;
}else{
$this->errorMessage.= $user_name;
}
}
public function get_euros($user_name){
if(!empty($user_name)){
$this->user_name->$user_name;
$array=array(':userName' => secure_prepare_db($user_name));
$euros = $this->query_fetchObject('SELECT euros FROM
players WHERE userName=\''.secure_db($user_name).'\'');
$this->euroMessage.= ''+ $euros ;
}else{
$this->errorMessage.= $user_name;
}
}
}
?>
非常感谢您的帮助