简体   繁体   English

PHP和DB与mysqli的连接

[英]PHP and DB connections with mysqli

I know this question may be a bit general but I have some questions that I would like to ask. 我知道这个问题可能有点笼统,但是我想问一些问题。

First of all I had a guy that did a website with some DB connections, etc, but now he left so I will have to continue his work soon. 首先,我有一个人在建立一个具有数据库连接等功能的网站,但现在他离开了,所以我将不得不继续他的工作。 I've access to all the job he did but I have no idea how can I 'see' the website locally since it only have PHP files and I have some problems while trying to connect to the remote database. 我可以访问他所做的所有工作,但是我不知道如何在本地“查看”该网站,因为该网站只有PHP文件,并且在尝试连接到远程数据库时遇到一些问题。 The error while connecting to the DB is: 连接到数据库时的错误是:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): There was an error while trying to connect because the host did not answer in time or maybe there was an error in the connection. 警告:mysqli :: mysqli()[mysqli.mysqli]:(HY000 / 2002):尝试连接时发生错误,因为主机未及时应答,或者连接中可能存在错误。 (It's a traduction so maybe the original English error is a bit different.) (这是一个推论,因此原始的英语错误可能有所不同。)

The connection is done by: 通过以下方式完成连接:

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);

So, my question is, how can I fix this to see that website locally so I could do all the tests I want before uploading it to the server. 因此,我的问题是,如何解决此问题以在本地查看该网站,以便在将其上传到服务器之前可以进行所有需要的测试。

Thanks for your time, Greetings. 谢谢您的宝贵时间,问候。

EDIT 编辑

I have a mysql server on another machine (on a hosting) and is working correctly (I can access with other applications I've done on Java and there is no problem). 我在另一台计算机上(位于主机上)有一个mysql服务器,并且工作正常(我可以使用在Java上完成的其他应用程序访问,没有问题)。 If I enter to the website online (I mean, uploaded to the hosting where I have the DB), the connecctions and everything works good. 如果我在线进入该网站(我的意思是,将其上传到拥有数据库的主机上),则连接和一切正常。

My problem is that I want to see the website locally to do internal test and do not destroy the online website, but as I already said, I can't connect to the DB. 我的问题是我想在本地看到该网站进行内部测试,并且不要破坏该在线网站,但是正如我已经说过的,我无法连接到数据库。

It could be something related to IPs? 可能与IP有关吗?

I'm pretty sure all the code works fine, problem is running it locally pretending to connect to an online DB. 我很确定所有代码都能正常工作,问题是在本地运行它并假装连接到在线数据库。

Do download the XAMPP and install it on ur machine. 请下载XAMPP并将其安装在您的计算机上。 then copy all the files and folder to xampp/htdocs/ and on the browser run like localhost/ and u wud be able to see all the files locally 然后将所有文件和文件夹复制到xampp / htdocs /,并在浏览器上像localhost /一样运行,您可以在本地查看所有文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM