Is there any way to connect to database using PDO and SSH tunnel and do not execute any code at command line like in the topic below?
Zend_Db: How to connect to a MySQL database over SSH tunnel?
Thanks in advance for your answer.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Without invoking the ssh tunnel within a seperate process, that means you will have to create a new tunnel for each invocation of the script – and you can’t share an tunnel created by another instance since you don’t know when it will terminate. So in addition to the connection overhead you need to manage a pool of local sockets.
The short answer is that it’s just not feasible.
A longer answer is that you can start daemons/long running processes from within PHP but there are a few caveats. So if you can use the program execution functions and have access to a set of POSIX tools using the command line tools then it is possible. It’ll be a lot simpler to implement this if you can set up a key pair (with an necryted private key) to avoid having to parse the I/O to the program to inject the password at the right point (or use something like ‘expect‘ to handle it).