I know this question has been asked several times before, but the solutions posted have not worked for me. I have tried all of them.
So here is my question
Q) I need to login to a @server using a username @username and password @password. On that server i have to use another password for mysql @sql_password and then start querying.
PUTTY
I start putty connect to @server, give @username and @password and i get connected. Then i issue mysql -p@sql_password
and i'm connected to mysql. Then i can use databases and start my queries.
But Now I need to do this in PHP!
PHP
First method :-
Use phpseclib to establish an SSH connection and then try connecting to mysql. Unfortunately when i issue themysql -p@sql_password
command my code just keeps running and i can see nothing on the screen. Now some solutions talked about using different syntaxes but nothing seems to work for me.
Here is the simple codeset_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib'); include('phpseclib/Net/SSH2.php'); $server=@server; $username=@username; $password=@password; $sql_password=@sql_password; $ssh = new Net_SSH2($server); if (!$ssh->login($username, $password)) { exit('Login Failed'); } echo $ssh->exec('whoami'); echo $ssh->exec('mysql -p@sql_password');
Second Method
use PHPShell_exec
command andplink
.
From the command line i can issueplink -ssh @username@@server -pw@password
and it seems to work properly. From there onwards its the same as putty. Now when i try usingshell_exec
in php it does'nt seem to work. For instanceecho shell_exec('plink');
gives me all the options of plink but when i runecho shell_exec ('plink -ssh @username@@server -pw@password');
it gives me nothing. I do awhoami
to try and figure out somethings and i getnt/authority system
,while on command line i see my proper username.
I am really lost here. Any help would be greatly appreciated.
thanks