Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "xxxx";
  4. $username = "xxxx";
  5. $password = "xxxx";
  6.  
  7. try {
  8.     $conn = new PDO("mysql:host=$servername;dbname=lyl2test", $username, $password);
  9.     // set the PDO error mode to exception
  10.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. }
  12. catch(PDOException $e)
  13. {
  14.     echo "Connection failed: " . $e->getMessage();
  15. }
  16.  
  17. $sql = "SELECT civ_licenses from players WHERE uid = 230";
  18.  
  19. foreach ($conn->query($sql) as $parseString) {
  20.     $parseString['civ_licenses'] = str_replace('"[', '[', $parseString['civ_licenses']);
  21.     $parseString['civ_licenses'] = str_replace(']"', ']', $parseString['civ_licenses']);
  22.     $parseString['civ_licenses'] = str_replace('`', '"', $parseString['civ_licenses']);
  23. }
  24.  
  25. if(!$obj = json_decode($parseString['civ_licenses'])) {
  26.     echo json_last_error_msg();
  27. }
  28.  
  29. foreach($obj as $key => $value) {
  30.     echo $value[0];
  31.     if($value[1] === 1) {
  32.         echo " vorhanden";
  33.     } else {
  34.         echo " nicht vorhanden";
  35.     }
  36.     echo "<br>";
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement