title: iOS connection does not return data
body: <p>I've been making a web service for a simple iOS user system. PHP queries perfectly, but one issue - iOS isn't working out very well. Data isn't being received. How do I proceed? Here's my connection class:</p>
  
  <pre><code>import Foundation
  
  class Connection: NSObject {
      var data: NSMutableData = NSMutableData()
  
      func login(username: String, password: String) {
          var url: NSURL = NSURL(string: "localhost/getusers.php?username=" + username + "&amp;password=" + password)!
          var request: NSURLRequest = NSURLRequest(URL: url)
          var conn: NSURLConnection = NSURLConnection(request: request, delegate: self, startImmediately: true)!
      }
  
      func connection(didReceiveResponse: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
          println("didReceiveResponse")
      }
  
      func connection(connection: NSURLConnection!, didReceiveData conData: NSData!) {
          self.data.appendData(conData)
      }
  
      func connectionDidFinishLoading(connection: NSURLConnection!) {
          println(self.data)
      }
  
      deinit {
          println("deiniting")
      }
  }
  </code></pre>
  
  <p>Here's where it's being called.</p>
  
  <pre><code>@IBAction func attemptLogin(sender: UIButton) {
          if(usernameTextField.text == "" || passwordTextField.text == "") {
              var alert = UIAlertController(title: "Error", message: "Invalid Credentials", preferredStyle: UIAlertControllerStyle.Alert)
              alert.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Default, handler: nil))
              self.presentViewController(alert, animated: true, completion: nil)
  
              var connection: Connection = Connection()
              connection.login(usernameTextField.text, password: passwordTextField.text)
          }
      }
  </code></pre>
  
  <p>Lastly, here's the PHP service:</p>
  
  <pre><code>error_reporting(E_ALL);
  ini_set('display errors', 1);
  
  $username = 'root';
  $password = 'root';
  
  try {
      $DBH = new PDO('mysql:host=localhost; dbname=login_test', $username, $password);
      $DBH-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      $recievedUsername = $_GET['username'];
      $recievedPassword = $_GET['password'];
  
      $data = array($recievedUsername, $recievedPassword);
  
      $STH = $DBH-&gt;prepare("SELECT id, first_name, last_name FROM `users` WHERE `username` = ? AND `password` = ?");
      $STH-&gt;execute($data);
  
      $row = $STH-&gt;fetch(PDO::FETCH_ASSOC);
      echo json_encode($row);
  } catch(PDOException $e) {
      echo $e-&gt;getMessage();
  }
  </code></pre>