text: Q:
  
  PHP Licence key with remote MySQL
  
  I created an database with this table
      CREATE TABLE IF NOT EXISTS `software` (
    `ID` int(255) NOT NULL AUTO_INCREMENT,
    `CompanyName` varchar(255) NOT NULL,
    `valid` int(1) NOT NULL DEFAULT '0',
    `license` varchar(255) NOT NULL,
    PRIMARY KEY (`ID`)
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
  
  and make a licence.php on another server to connect with remote mysql
          <?php
      function connect(){
  $dsn = 'mysql:dbname=NAME;host=xx.xx.xx.xx';
  $user = 'USER';
  $password = 'PASS';
  try {
      $dbh = new PDO($dsn, $user, $password);
      // run query
      $license = "test";
      $sth = $dbh->prepare("SELECT * FROM software WHERE license='$license' AND valid='1'");
      $sth->execute();
      $result = $sth->fetchAll();
      if ($sth->rowCount() < 1) {
          die("Your License Has Expired!");
      }
  } catch (PDOException $e) {
      echo 'Connection failed: ' . $e->getMessage();
  }
  }
      ?>
  
  Update:nothing happened!! just blank page in both way (valid=0) or (valid=1)
  What is the problem?
  
  A:
  
  Your issue is that you're defining the connect() function and not calling it. It seems like redundant coding that you have going on.
  You should simply just run something like this:
  $dsn = 'mysql:dbname=NAME;host=xx.xx.xx.xx';
  $user = 'USER';
  $password = 'PASS';
  try {
      $dbh = new PDO($dsn, $user, $password);
      // run query
      $license = "test";
      $sth = $dbh->prepare("SELECT * FROM software WHERE license='$license' AND valid='1'");
      $sth->execute();
      $result = $sth->fetchAll();
      if ($sth->rowCount() < 1) {
          die("Your License Has Expired!");
      }
  } catch (PDOException $e) {
      echo 'Connection failed: ' . $e->getMessage();
  }
  
  Also, instead of doing:
  if (count($result) === 0) {
  
  You should use the native PDO rowCount
  if($sth->rowCount() < 1) {....
  
  The above will check if the row count is less than 1 (effectively 0)
  
  