简体   繁体   English

是否可以在本地项目中使用在线数据库?

[英]Is it possible to use online databases in a local project?

Here is my database connection: 这是我的数据库连接:

// connect to database and select database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "spy";
$dbh_conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$dbh_conn->exec("set names utf8");
$dbh_conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

It works fine since the database is exists in the local. 由于数据库存在于本地中,因此可以正常工作。 Now I've uploaded the database on a server and I want to use that online database (instead of the local one) . 现在,我已将数据库上传到服务器上,并且希望使用该在线数据库(而不是本地数据库 Is it possible? 可能吗? If yes, what should I write as servername ? 如果是,我应该写为servername吗?


在此处输入图片说明

All you need to do is set $servername to the host address of the remote server and provide the correct credentials. 您需要做的只是将$servername设置$servername remote server的主机地址,并提供正确的凭据。 Provided the server is allowing connections, you should be able to connect to its database. 如果服务器允许连接,则您应该能够连接到其数据库。

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

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