Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. try {
  2.  
  3. $host = 'remote host';
  4. $sshuser = 'ssh user';
  5. $sshpass = 'ssh password';
  6. $dbuser = 'db user';
  7. $dbpass = 'db user';
  8. $dbname = 'db name';
  9.  
  10. shell_exec("ssh -p$sshpass ssh -o StrictHostKeyChecking=no -f -L 3307:127.0.0.1:3306 $sshuser@$host");
  11.  
  12. $dbh = new PDO('mysql:host=127.0.0.1;port=3307;dbname=' .$dbname. '', $dbuser, $dbpass);
  13.  
  14. $sth = $dbh->prepare("SELECT * from table");
  15.  
  16. $sth->execute();
  17.  
  18. $result = $sth->fetchAll();
  19.  
  20. print_r ($result);
  21.  
  22. shell_exec("kill $(ssh-pid)");
  23.  
  24. $dbh = null;
  25. } catch (PDOException $e) {
  26. print "Error!: " . $e->getMessage() . "<br/>";
  27. die();
  28. }
  29.  
  30. Error!: SQLSTATE[HY000] [1130] Host 'host' is not allowed to connect to this MySQL server
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement