<tfoot id='YtTiI'></tfoot>
      <bdo id='YtTiI'></bdo><ul id='YtTiI'></ul>
  1. <i id='YtTiI'><tr id='YtTiI'><dt id='YtTiI'><q id='YtTiI'><span id='YtTiI'><b id='YtTiI'><form id='YtTiI'><ins id='YtTiI'></ins><ul id='YtTiI'></ul><sub id='YtTiI'></sub></form><legend id='YtTiI'></legend><bdo id='YtTiI'><pre id='YtTiI'><center id='YtTiI'></center></pre></bdo></b><th id='YtTiI'></th></span></q></dt></tr></i><div id='YtTiI'><tfoot id='YtTiI'></tfoot><dl id='YtTiI'><fieldset id='YtTiI'></fieldset></dl></div>

      <legend id='YtTiI'><style id='YtTiI'><dir id='YtTiI'><q id='YtTiI'></q></dir></style></legend>

      <small id='YtTiI'></small><noframes id='YtTiI'>

      通过 SSH 通过 PHP 连接到 mysql 数据库

      时间:2023-07-29
        <tbody id='hnKwY'></tbody>

        • <small id='hnKwY'></small><noframes id='hnKwY'>

          <tfoot id='hnKwY'></tfoot>
            <bdo id='hnKwY'></bdo><ul id='hnKwY'></ul>

            <legend id='hnKwY'><style id='hnKwY'><dir id='hnKwY'><q id='hnKwY'></q></dir></style></legend>

              1. <i id='hnKwY'><tr id='hnKwY'><dt id='hnKwY'><q id='hnKwY'><span id='hnKwY'><b id='hnKwY'><form id='hnKwY'><ins id='hnKwY'></ins><ul id='hnKwY'></ul><sub id='hnKwY'></sub></form><legend id='hnKwY'></legend><bdo id='hnKwY'><pre id='hnKwY'><center id='hnKwY'></center></pre></bdo></b><th id='hnKwY'></th></span></q></dt></tr></i><div id='hnKwY'><tfoot id='hnKwY'></tfoot><dl id='hnKwY'><fieldset id='hnKwY'></fieldset></dl></div>
                本文介绍了通过 SSH 通过 PHP 连接到 mysql 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我已经写了一个本地连接mysql数据库的php文件.现在,我想通过 SSH 连接到远程数据库.目前,我的数据库的连接函数在 php 中如下所示:

                $this->db = new mysqli(_SERVR_URL, _SERVR_USER, _SERVR_PASS, _SERVR_DB);如果 ($this->db->connect_errno) {echo "无法连接到 MySQL: (" . $this->db->connect_errno . ") ".$this->db->connect_error;}别的{//echo "连接成功!!

                ";}

                我只想更改连接函数(以上),以便其余代码仍然有效.我已经成功安装了 phpseclib 并且对安装 php 的 ssh 扩展不感兴趣,因为经过近 5 个小时的努力,这些扩展不起作用.phpseclib 正在工作,我认为这是因为当我使用 require 时它不会死.

                但是,当我尝试开始使用 ssh 内容时,它会引发服务器错误:

                $ssh = new Net_SSH1(myURL);

                我通常通过 SSH 连接到我的服务器的方式是使用 .pem 文件.我能否获得以下方面的指导:

                1. 为什么当前代码可能会抛出错误?
                2. 如果可能的话.
                3. 您将如何使用 .pem 文件编写连接代码.

                解决方案

                我认为您在这方面运气不佳.您可以使用 ssh您的 PHP 代码中的扩展名,或者如果您有权访问服务器,您可以尝试在命令行上创建 ssh 隧道.

                不过,您可能需要特殊权限才能执行此操作.它也是您似乎没有此托管帐户的 ssh 访问权限.

                重复@jpm 回答>

                设置隧道 由@Ólafur Waage 在 在 PHP 中通过 SSH 连接到 MySQL 服务器

                和这个用于@@索西

                shell_exec(ssh -f -L 3307:127.0.0.1:3306 user@remote.rjmetrics.com sleep 60 >> logfile");$db = mysqli_connect('127.0.0.1', 'sqluser', 'sqlpassword', 'rjmadmin', 3307);

                I have already written a php file that connects to the mysql database locally. Now, I want to connect to a remote database via SSH. Currently the connect function for my database is the following in php:

                $this->db = new mysqli(_SERVR_URL, _SERVR_USER , _SERVR_PASS, _SERVR_DB);
                    if ($this->db->connect_errno) {
                        echo "Failed to connect to MySQL: (" . $this->db->connect_errno . ") " . $this->db->connect_error;
                    }
                    else{
                        //echo "Successfully connected!! <BR><BR>";
                    }
                

                I want to only change the connect function (above) so that the rest of the code still works. I have successfully installed the phpseclib and am not interested in installing php's ssh extensions because those were not working after nearly 5 hours of effort. The phpseclib is working, and I think this because when I use require it does not die.

                However, when I try to start working with the ssh stuff, it throws a server error:

                $ssh = new Net_SSH1(myURL);
                

                The way that I usually SSH into my server is with a .pem file. Can I get some guidance on:

                1. Why the current code may be throwing an error?
                2. If this is possible.
                3. How would you write the connection code with the .pem file.

                解决方案

                I think you are out of luck on this one. You can either use the ssh extension in your PHP code, or if you have access to the server, you could try to create a ssh tunnel on the command-line.

                You probably need special permissions to do that, though. It also looks like you don't have ssh access to this hosting account.

                duplicate answered by @jpm

                Setting up tunneling posted by @Ólafur Waage on Connect to a MySQL server over SSH in PHP

                And this one for tunneling by @Sosy

                shell_exec("ssh -f -L 3307:127.0.0.1:3306 user@remote.rjmetrics.com sleep 60 >> logfile");  
                $db = mysqli_connect(’127.0.0.1′, ‘sqluser’, ‘sqlpassword’, ‘rjmadmin’, 3307);
                

                这篇关于通过 SSH 通过 PHP 连接到 mysql 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:mysqli_stmt_close() 期望参数 1 是 mysqli_stmt,布尔值 下一篇:使用 MySQLi 准备语句时无法获取行数和获取

                相关文章

                最新文章

              2. <legend id='oPMNI'><style id='oPMNI'><dir id='oPMNI'><q id='oPMNI'></q></dir></style></legend>
                  <bdo id='oPMNI'></bdo><ul id='oPMNI'></ul>

              3. <small id='oPMNI'></small><noframes id='oPMNI'>

                <tfoot id='oPMNI'></tfoot>

                    <i id='oPMNI'><tr id='oPMNI'><dt id='oPMNI'><q id='oPMNI'><span id='oPMNI'><b id='oPMNI'><form id='oPMNI'><ins id='oPMNI'></ins><ul id='oPMNI'></ul><sub id='oPMNI'></sub></form><legend id='oPMNI'></legend><bdo id='oPMNI'><pre id='oPMNI'><center id='oPMNI'></center></pre></bdo></b><th id='oPMNI'></th></span></q></dt></tr></i><div id='oPMNI'><tfoot id='oPMNI'></tfoot><dl id='oPMNI'><fieldset id='oPMNI'></fieldset></dl></div>