从不同的网络连接到MySQL数据库?

I've created a database using Microsoft Azure Portal (MySQL Database).

Currently I'm using PHP to connect to the database.

$servername = "server.mysql.database.azure.com";
$username = "username@server";
$password = "password";
$dbname = "database";



// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, 3306);
// Check connection

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

SQL queries to populate data in JSON format.

$sql = "SELECT id, username, score FROM ScoreTable";
$result = $conn->query($sql);

$dbdata = array();
 while ( $row = $result->fetch_assoc())  {
    $dbdata[]=$row;
  }

echo json_encode($dbdata);

Result (localhost/jubakee.php OR http://192.168.1.7/jubakee.php (local IP) both produce the same results).

[{"id":"1","username":"Stacey","score":"500"},
{"id":"2","username":"SJ","score":"600"}]

The issue I am having is that I want to be able to access this database from different networks e.g on 3G/4G or my friend's house.

When trying to load http://192.168.1.7/jubakee.php on my android device it will only produce the results if I'm on the same network as my PC (Same Wi-Fi Network).

When I switch my network from Wi-Fi to Mobile Data (3G) I can no longer access the database and http://192.168.1.7/jubakee.php will not load.

The purpose of this is so I can create an online database which will interact with my C# android application. The database will store the scores of the users.

How can I allow users using different networks to connect to my database?

Thank you.

1个回答



您无法从蜂窝数据或不同的wifi网络访问xamp服务器。 你必须在像000webhost这样的实时服务器上传你的数据库和文件然后你会有一个像 http:/ /YOURWEBSITE.000webhost.com/jubakee.php 。 现在,您可以随时随地在任何应用程序中访问此URL。</ p>
</ div>

展开原文

原文

You can't not access the xamp server from your cellular data or different wifi networks. You have to upload your database and files in a live server like 000webhost then you will have a url like http://YOURWEBSITE.000webhost.com/jubakee.php. Now you can access this url from anywhere, anytime and in any applications.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐