Good day. The following snag occurred:
I use windows with WAMP installed. The hosting service provider allows you to connect to the database only via SSH2 (it is correct), but you cannot connect to the database. Do the following
$ssh_server='93.125.xx.xx'; //адрес сервера $ssh_port='22'; //порт сервера $ssh_user=''; //логин от сервера $ssh_password=''; //пароль от сервера $ssh_connection=ssh2_connect($ssh_server, $ssh_port); $ssh_auth=ssh2_auth_password($ssh_connection, $ssh_user, $ssh_password); $ssh_tunnel = ssh2_tunnel($ssh_connection, $ssh_server, $ssh_port); Here everything goes with a bang. Then I check and try to connect to the database. But I did not understand how using the tunnel created to connect
if ($ssh_connection and $ssh_auth and $ssh_tunnel) { $db_hostname = '127.0.0.1'; $db_database = ''; //имя БД mysql $db_username = ''; //имя пользоватля БД $db_password = ''; //пароль пользователя БД $db_port = '3306'; $connection_mysql = new mysqli($db_hostname, $db_username, $db_password, $db_database, $db_port); if ($connection_mysql->connect_error) exit($connection_mysql->connect_error); mysqli_set_charset($connection_mysql, "utf8"); } It gives a standard connection error
Access denied for user 'igcby_gpresults' @ 'localhost' (using password: YES)
But apparently it just connects to my local database, but I don’t have one on my machine.
If you try to substitute ssh variables as $db_hostname , then nothing will come out of the way. For variables $ ssh_connection, $ ssh_auth, $ ssh_tunnel produces, respectively:
mysqli :: __ construct () expects parameter 1 to be string, resource given
mysqli :: __ construct (): php_network_getaddresses: getaddrinfo failed
mysqli :: __ construct () expects parameter 1 to be string, resource given
var_dump three ssh variables
var_dump($ssh_connection); var_dump($ssh_auth); var_dump($ssh_tunnel); gives the following
resource (2) of type (SSH2 Session)
bool (true)
resource (3) of type (stream)
If you specify the server address itself as $db_hostname , as when connecting via ssh ($ ssh_server = '93 .125.xx.xx '; and also $db_hostname='93.125.xx.xx'; ), there will be no sense (mysqli :: __ construct (): (HY000 / 2002): and a bunch of diamonds with questions - something with an encoding)
How to be, tell me, please.