Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. <?php
  2. //MOPlayer: manage all interactions with the player_name MySQL table
  3. Class UMACharacterCustomization extends MODb{
  4. //character name
  5. private $name;
  6. private $errorMessage=null;
  7. private $dollarMessage=null;
  8. private $euroMessage=null;
  9. private $dollars=null;
  10. private $euros=null;
  11.  
  12. // Constructor
  13. function __construct($user, $pass, $host, $dbName){
  14. parent::__construct($user, $pass, $host, $dbName);
  15. }
  16.  
  17. // Destructor
  18. function __destruct(){
  19. parent::__destruct();
  20. }
  21.  
  22. // Getter
  23. public function __get($nom){
  24. if(isset($this->$nom)){
  25. return $this->$nom;
  26. }
  27. }
  28.  
  29. //Save the player_name
  30. public function playername($name,$user_name){
  31. if(!empty($name)&&!empty($user_name)){
  32. $this->name->$name;
  33. $this->user_name->$user_name;
  34. $array = array(
  35. ':player_id' => '',
  36. ':player_name' => secure_prepare_db($name),
  37. ':userName' => secure_prepare_db($user_name)
  38. );
  39. // $array=array(':player_id' => '',
  40. //':player_name' => secure_prepare_db($this->$name));
  41.  
  42. $this->prepare_exec('INSERT INTO players(player_id,player_name,userName) VALUES(:player_id,:player_name,:userName)', $array);
  43. }else{
  44. $this->errorMessage.= $name;
  45. }
  46. return false;
  47. }
  48.  
  49.  
  50. public function get_dollars($user_name){
  51. if(!empty($user_name)){
  52. $this->user_name->$user_name;
  53. $array=array(':userName' => secure_prepare_db($user_name));
  54.  
  55. $dollars = $this->query_fetchObject('SELECT dollars FROM
  56. players WHERE userName=''.$user_name.''');
  57.  
  58. $this->dollarMessage.= $dollars->dollars ;
  59.  
  60. }else{
  61. $this->errorMessage.= $user_name;
  62. }
  63. }
  64.  
  65. public function get_euros($user_name){
  66. if(!empty($user_name)){
  67. $this->user_name->$user_name;
  68. $array=array(':userName' => secure_prepare_db($user_name));
  69.  
  70. $euros = $this->query_fetchObject('SELECT euros FROM
  71. players WHERE userName=''.secure_db($user_name).''');
  72.  
  73.  
  74. $this->euroMessage.= ''+ $euros ;
  75.  
  76. }else{
  77. $this->errorMessage.= $user_name;
  78. }
  79. }
  80.  
  81.  
  82. }
  83. ?>
  84.  
  85. public IEnumerator GetDollars(string user_name){
  86. int dollars;
  87. int euros;
  88. WWW www = new WWW (url + "GetMoney.php"+"?dollars=1&userName="+user_name);
  89. yield return www;
  90. if (www.isDone) {
  91. string trimText = www.text.Trim();
  92. if(trimText == "Success") {
  93. Debug.Log("Success");
  94. } else {
  95. Debug.Log ("dollars: "+www.text.Trim());
  96. }
  97. }
  98. }
  99.  
  100. public IEnumerator GetEuros(string user_name){
  101. int dollars;
  102. int euros;
  103. WWW www = new WWW (url + "GetMoney.php"+"?euros=1&userName="+user_name);
  104. yield return www;
  105. if (www.isDone) {
  106. string trimText = www.text.Trim();
  107. if(trimText == "1") {
  108. Debug.Log("Success");
  109. } else {
  110. Debug.Log ("euros: "+www.text.Trim());
  111. }
  112. }
  113. }
  114.  
  115. <?php
  116. /* MODb : this PHP class is used for the connections and queries to MySQL
  117. * This class is the mother of all others
  118. */
  119.  
  120. class MODb {
  121.  
  122. /**************** YOU MUST COMPLETE THESE PARAMETERS ********************/
  123. // Enter here your database username :
  124. private $user;
  125. // Enter here your database passwords :
  126. private $pass;
  127. // Enter here your database server (it's often "localhost") :
  128. private $host;
  129. // Enter here the name of your database :
  130. private $dbName;
  131. /*********************************************************************/
  132.  
  133. private $connect;
  134. protected $dbResult;
  135.  
  136. // Connect to MySQL
  137. function __construct($user, $pass, $host, $dbName){
  138. $this->user=$user;
  139. $this->pass = $pass;
  140. $this->host=$host;
  141. $this->dbName=$dbName;
  142.  
  143. try{
  144. $dns = 'mysql:host='.$this->host.';dbname='.$this->dbName;
  145. $bdd = new PDO($dns, $this->user, $this->pass);
  146. $this->connect = $bdd;
  147. }catch(PDOExeption $e){
  148. $this->getError($e);
  149. }
  150. }
  151.  
  152. function __destruct(){
  153. $this->close();
  154. }
  155.  
  156. // Close connect
  157. public function close(){
  158. $this->connect = NULL;
  159. }
  160.  
  161. // Get error
  162. private function getError($e){
  163. echo 'Error ! :'.$e->getMessage().'<br>';
  164. echo 'N° : '.$e->getCode();
  165. exit();
  166. }
  167.  
  168. // Simple query to MySQL
  169. public function query($query){
  170. try{
  171. $data = $this->connect->query($query);
  172. return $data;
  173. }catch(PDOException $e){
  174. $this->getError($e);
  175. }
  176. }
  177.  
  178. // Get the last saved ID
  179. public function lastId(){
  180. return $this->connect->lastInsertId();
  181. }
  182.  
  183. public function fetch($query){
  184. try{
  185. $data = $query->fetch(PDO::FETCH_ASSOC);
  186. $query->closeCursor();
  187. return $data;
  188. }catch(PDOException $e){
  189. $this->getError($e);
  190. }
  191. }
  192.  
  193. // Return the result of a query with fetchObject
  194. public function fetchObjet($query){
  195. try{
  196. $data = $query->fetchObject();
  197. $query->closeCursor();
  198. return $data;
  199. }catch(PDOException $e){
  200. $this->getError($e);
  201. }
  202. }
  203.  
  204. // Return the result of a query with fetchAll
  205. public function fetchAll($query){
  206. try{
  207. $data = $query->fetchAll(PDO::FETCH_ASSOC);
  208. $query->closeCursor();
  209. return $data;
  210. }catch(PDOException $e){
  211. $this->getError($e);
  212. }
  213. }
  214.  
  215. // Simpe exec
  216. public function exec($var){
  217. try{
  218. $query = $this->connect->exec($var);
  219. }catch(PDOException $e){
  220. $this->getError($e);
  221. }
  222. }
  223.  
  224. // Query MySQL return with fetchAll
  225. public function query_fetchAll($var){
  226. try{
  227. $query = $this->connect->query($var);
  228. $data = $query->fetchAll(PDO::FETCH_ASSOC);
  229. $query->closeCursor();
  230. return $data;
  231. }catch(PDOException $e){
  232. $this->getError($e);
  233. }
  234. }
  235.  
  236. // Query MySQL return with fetchObject
  237. public function query_fetchObject($var){
  238. try{
  239. $query = $this->connect->query($var);
  240. $data = $query->fetchObject();
  241. $query->closeCursor();
  242. return $data;
  243. }catch(PDOException $e){
  244. $this->getError($e);
  245. }
  246. }
  247.  
  248. // Pepare and execute a query
  249. public function prepare_exec($var, $var_array){
  250. try{
  251. $query = $modele = $this->connect->prepare($var);
  252. $modele->execute($var_array);
  253. }catch(PDOException $e){
  254. $this->getError($e);
  255. }
  256. }
  257. }
  258. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement