doujia6433 2019-04-06 07:53
浏览 153
已采纳

从不同的网络连接到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条回答 默认 最新

  • doudou8783 2019-04-06 12:26
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图