[英]Using php connect to production server in local machine
I have some existing code in php for server side coding and the db is MySql. 我在php中已有一些用于服务器端编码的代码,而数据库是MySql。 Both resides on the production(realtime) database.
两者都驻留在生产(实时)数据库上。
Some job is given to me to fetch the records from the actual server and display in some format on local machine. 我得到了一些工作,可以从实际服务器中获取记录并以某种格式显示在本地计算机上。 I cannot duplicate the data onto my local system due to security reason.
由于安全原因,我无法将数据复制到本地系统上。 Any ideas how can i connect to production server and get my query run.
任何想法如何连接到生产服务器并运行查询。 I am ready to recreate the server side coding also....any help is appreciated....
我也准备重新创建服务器端编码。
You will need to grant access to the production machine from your local machine. 您将需要从本地计算机授予对生产计算机的访问权限。 You can do so by granting all privileges on your IP address.
您可以通过授予IP地址上的所有特权来做到这一点。 For example, if your username was
remote
and your public IP address was 10.1.0.8
, you would use this: 例如,如果您的用户名是
remote
用户,而您的公共IP地址是10.1.0.8
,则可以使用以下命令:
GRANT ALL PRIVILEGES ON *.* TO remote@'10.1.0.8';
FLUSH PRIVILEGES;
Remember to flush your updated privileges! 记住要刷新更新的权限!
You can now connect to the production machine using PHP. 现在,您可以使用PHP连接到生产机器。 For example, if your production machine was at
production.example.com
, you would use this: 例如,如果您的生产机器位于
production.example.com
,则可以使用以下命令:
mysql_connect("production.example.com", "remote", "My-p@ssw0rd");
mysql_select_db("example_db");
If you don't have root access to the production machine or can't grant privileges for some reason, you can also try to set up an SSH tunnel, if you have access to SSH. 如果您无权访问生产计算机或由于某种原因不能授予特权,那么如果您有权访问SSH,则还可以尝试建立SSH隧道。
Instructions on how to set up an SSH tunnel can be found here (Windows/PuTTY). 有关如何设置SSH隧道的说明,请参见此处 (Windows / PuTTY)。
You can then connect to whatever you used as local port using PHP as PuTTY will route all traffic through its SSH tunnel to the remote production server, making the production server to believe you connected from localhost
: 然后,您可以使用PHP连接到您用作本地端口的任何端口,因为PuTTY会将所有流量通过其SSH隧道路由到远程生产服务器,从而使生产服务器相信您已从
localhost
连接:
mysql_connect("localhost", "remote", "My-p@ssw0rd");
mysql_select_db("example_db");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.