Objective C - 无法查询数据库(MySQL)

I'm trying to work on a personal project and i'm implementing a login system. At the moment I would like the application to connect to a database and query information within that database i.e a username and password. At the minute I do believe my application successfully connects to the database, but querying the table isn't working for some reason.

Here's the code i've got within xCode for the application to connect to the PHP file located on my server that then connects to the database:

- (IBAction)login:(id)sender {

    NSInteger success = 0;
    @try {

        if([[self.txtEmail text] isEqualToString:@""] || [[self.txtPassword text] isEqualToString:@""] ) {

            [self alertStatus:@"Please enter Email and Password" :@"Sign in Failed!" :0];

        } else {
            NSString *post =[[NSString alloc] initWithFormat:@"username=%@&password=%@",[self.txtEmail text],[self.txtPassword text]];
            NSLog(@"PostData: %@",post);

            NSURL *url=[NSURL URLWithString:@"http://repayment.tk/app_login.php"];

            NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

            NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
            [request setURL:url];
            [request setHTTPMethod:@"POST"];
            [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
            [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            [request setHTTPBody:postData];

            //[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];

            NSError *error = [[NSError alloc] init];
            NSHTTPURLResponse *response = nil;
            NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

            NSLog(@"Response code: %ld", (long)[response statusCode]);

            if ([response statusCode] >= 200 && [response statusCode] < 300)
            {
                NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
                NSLog(@"Response ==> %@", responseData);

                NSError *error = nil;
                NSDictionary *jsonData = [NSJSONSerialization
                                          JSONObjectWithData:urlData
                                          options:NSJSONReadingMutableContainers
                                          error:&error];

                success = [jsonData[@"success"] integerValue];
                NSLog(@"Success: %ld",(long)success);

                if(success == 1)
                {
                    NSLog(@"Login SUCCESS");
                } else {

                    NSString *error_msg = (NSString *) jsonData[@"error_message"];
                    [self alertStatus:error_msg :@"Sign in Failed!" :0];
                }

            } else {
                //if (error) NSLog(@"Error: %@", error);
                [self alertStatus:@"Connection Failed" :@"Sign in Failed!" :0];
            }
        }
    }
    @catch (NSException * e) {
        NSLog(@"Exception: %@", e);
        [self alertStatus:@"Sign in Failed." :@"Error!" :0];
    }
    if (success) {
        [self performSegueWithIdentifier:@"login_success" sender:self];
    }
}

- (void) alertStatus:(NSString *)msg :(NSString *)title :(int) tag
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                        message:msg
                                                       delegate:self
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil, nil];
    alertView.tag = tag;
    [alertView show];
}

Here's the contents of the PHP file that Xcode connects to:

<?php

class LoginHandler {

    public $dbHostname = 'mysql.hostinger.co.uk';
    public $dbDatabaseName = 'DATABASE NAME';
    public $user = 'ADMIN USER';
    public $password = 'PASSWORD';

    public function handleRequest($arg) {

        $username = $arg['username'] ? $arg['username']: null;
        $password = $arg['password'] ? $arg['password']: null;
        if ( ! $username || ! $password ) {
            $this->fail();
            return;
        }

        try  {
            $dsn = "mysql:dbname={$this->dbHostname};host={$this->dbHostname}";

            $pdo = new PDO($dsn, $this->user, $this->password);
            $sql="SELECT * FROM `user` WHERE `username`='$username' and `password`='$password'";
            $stmt = $pdo->query($sql);
            if ( $stmt->rowCount() > 0 ) {
                $this->success();
                return;
            }
            else {
                $this->fail();
                return;
            }
        }
        catch(PDOException $e) {
            $this->log('Connection failed: ' . $e->getMessage());
            $this->fail();
        }


    }
    function success() {
        echo json_encode(['success' => 1]);
    }
    function fail() {
        echo json_encode(['success' => 0]);
    }

    function log($msg) {
        file_put_contents("login.log", strftime('%Y-%m-%d %T ') . "$msg
", FILE_APPEND);
    }
}

$handler = new LoginHandler();
$handler->handleRequest($_POST);

The application runs, loads and seems to allow data to be inputted absoutely fine. It's just upon entering a username & password I always get the error message saying "Login Failed!" even though i've made sure the table contains both the corresponding username and password. Any help would be greatly appreciated, i seem to have hit a brick wall with this at the minute.

Also i don't know if this is relevant at all put looking at my xcode output box i can see the following message and i'm wondering if this is the cause at all:

2016-03-14 11:43:10.956 Repayment Calculator[6539:2753208] PostData: username=a&password=a
2016-03-14 11:43:10.956 Repayment Calculator[6539:2753208] -[NSError init] called; this results in an invalid NSError instance. It will raise an exception in a future release. Please call errorWithDomain:code:userInfo: or initWithDomain:code:userInfo:. This message shown only once.
2016-03-14 11:43:11.237 Repayment Calculator[6539:2753208] Response code: 200
2016-03-14 11:43:11.238 Repayment Calculator[6539:2753208] Response ==> {"success":0}
2016-03-14 11:43:11.238 Repayment Calculator[6539:2753208] Success: 0

Here's also the contents from the table 'user' in SQL:

-- phpMyAdmin SQL Dump
-- version 3.5.2.2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Mar 14, 2016 at 12:04 PM
-- Server version: 10.0.20-MariaDB
-- PHP Version: 5.2.17

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `u948870604_data`
--

-- --------------------------------------------------------

--
-- Table structure for table `user`
--

CREATE TABLE IF NOT EXISTS `user` (
  `username` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `password` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  `email` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`username`, `password`, `email`) VALUES
('a', 'a', 'a');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

I believe this might be the solution to your problem - recent changes in XCode with http vs https:

NSURL Error Code 1022