Frage

I got a problem. My PHP script abort if i run an mysql command:

ssh2_exec($session, 'mysql -sse "SELECT COUNT(*) FROM table"');

With putty is the command no problem. Any other commands like 'll -la' or what else are no problem.

Can u tell me why it isn't working?

Bye mok

War es hilfreich?

Lösung 2

Okay... i got it now.

The command "mysql" is in my system an alias to "mysql -u user -ppassword". But if u do a connection wit ssh2_exec() all alias are unknown.

All i have to do is this.

ssh2_exec($session, 'mysql -u user -ppassword -sse "SELECT COUNT(*) FROM table"');

Thank U!

Andere Tipps

I don't know the -sse option, but I guess your problem is that ssh2_exec returns a stream and not a string.

You can try using:

$stream = ssh2_exec($session, 'echo "SELECT COUNT(*) FROM table" | mysql');
$output = stream_get_contents($stream);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top