Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //MOPlayer: manage all interactions with the player_name MySQL table
- Class UMACharacterCustomization extends MODb{
- //character name
- private $name;
- private $errorMessage=null;
- private $dollarMessage=null;
- 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.= $dollars->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;
- }
- }
- }
- ?>
- public IEnumerator GetDollars(string user_name){
- int dollars;
- int euros;
- WWW www = new WWW (url + "GetMoney.php"+"?dollars=1&userName="+user_name);
- yield return www;
- if (www.isDone) {
- string trimText = www.text.Trim();
- if(trimText == "Success") {
- Debug.Log("Success");
- } else {
- Debug.Log ("dollars: "+www.text.Trim());
- }
- }
- }
- public IEnumerator GetEuros(string user_name){
- int dollars;
- int euros;
- WWW www = new WWW (url + "GetMoney.php"+"?euros=1&userName="+user_name);
- yield return www;
- if (www.isDone) {
- string trimText = www.text.Trim();
- if(trimText == "1") {
- Debug.Log("Success");
- } else {
- Debug.Log ("euros: "+www.text.Trim());
- }
- }
- }
- <?php
- /* MODb : this PHP class is used for the connections and queries to MySQL
- * This class is the mother of all others
- */
- class MODb {
- /**************** YOU MUST COMPLETE THESE PARAMETERS ********************/
- // Enter here your database username :
- private $user;
- // Enter here your database passwords :
- private $pass;
- // Enter here your database server (it's often "localhost") :
- private $host;
- // Enter here the name of your database :
- private $dbName;
- /*********************************************************************/
- private $connect;
- protected $dbResult;
- // Connect to MySQL
- function __construct($user, $pass, $host, $dbName){
- $this->user=$user;
- $this->pass = $pass;
- $this->host=$host;
- $this->dbName=$dbName;
- try{
- $dns = 'mysql:host='.$this->host.';dbname='.$this->dbName;
- $bdd = new PDO($dns, $this->user, $this->pass);
- $this->connect = $bdd;
- }catch(PDOExeption $e){
- $this->getError($e);
- }
- }
- function __destruct(){
- $this->close();
- }
- // Close connect
- public function close(){
- $this->connect = NULL;
- }
- // Get error
- private function getError($e){
- echo 'Error ! :'.$e->getMessage().'<br>';
- echo 'N° : '.$e->getCode();
- exit();
- }
- // Simple query to MySQL
- public function query($query){
- try{
- $data = $this->connect->query($query);
- return $data;
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Get the last saved ID
- public function lastId(){
- return $this->connect->lastInsertId();
- }
- public function fetch($query){
- try{
- $data = $query->fetch(PDO::FETCH_ASSOC);
- $query->closeCursor();
- return $data;
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Return the result of a query with fetchObject
- public function fetchObjet($query){
- try{
- $data = $query->fetchObject();
- $query->closeCursor();
- return $data;
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Return the result of a query with fetchAll
- public function fetchAll($query){
- try{
- $data = $query->fetchAll(PDO::FETCH_ASSOC);
- $query->closeCursor();
- return $data;
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Simpe exec
- public function exec($var){
- try{
- $query = $this->connect->exec($var);
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Query MySQL return with fetchAll
- public function query_fetchAll($var){
- try{
- $query = $this->connect->query($var);
- $data = $query->fetchAll(PDO::FETCH_ASSOC);
- $query->closeCursor();
- return $data;
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Query MySQL return with fetchObject
- public function query_fetchObject($var){
- try{
- $query = $this->connect->query($var);
- $data = $query->fetchObject();
- $query->closeCursor();
- return $data;
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- // Pepare and execute a query
- public function prepare_exec($var, $var_array){
- try{
- $query = $modele = $this->connect->prepare($var);
- $modele->execute($var_array);
- }catch(PDOException $e){
- $this->getError($e);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement