title: Phpseclib connect MYSQL server
body: <p>I want to connect to my remote MySQL server through port forwarding. Unfortunately my hosting provider don't have <code>php_ssh2</code> installed on the server so I have to work through <code>phpseclib</code> library. So far I am able to do:</p>
  
  <p>1 - Connect to server using <code>Net_SSH2</code>:</p>
  
  <pre><code>$ssh = new Net_SSH2('xx.xxx.xx.xx');  
   if (!$ssh-&gt;login('user', 'password')) {  
      exit('Login Failed');  
   }  
  </code></pre>
  
  <p>If I do <code>echo $ssh-&gt;exec('ls -la');</code>, it fetches directory listing telling we are connected successfully.   </p>
  
  <p>if I run </p>
  
  <p>2 - <code>echo $ssh-&gt;exec('echo "select * from table where company_id=\"15\";" | mysql');</code></p>
  
  <p>It triggers:   </p>
  
  <blockquote>
    <p>stdin: is not a tty ERROR 1045 (28000): Access denied for user
    'user'@'localhost' (using password: NO)</p>
  </blockquote>
  
  <p>3 - If I do <code>echo $ssh-&gt;exec('ssh -f -L 3307:localhost:3306 root@xx.xxx.xxx.xxx sleep 60 &gt;&gt; logfile');</code></p>
  
  <p>It runs forever resulting in no response error from the server.</p>
  
  <p>I am pulling my hair out. HELP!!!!!</p>