简体   繁体   English

使用实际设备连接到xampp localhost数据库

[英]connect to the xampp localhost database with the real device

我可以使用andoird模拟器连接到xampp本地主机数据库,但是当我在真实设备上尝试连接时,它没有连接。有什么方法可以将我的android设备连接到本地主机xampp数据库。谢谢。

Localhost to your machine and localhost to your android device isn't the same. 您的计算机的本地主机和android设备的本地主机是不同的。 When using localhost it typically references the current device that the code is being executed on. 使用localhost时,它通常引用在其上执行代码的当前设备。

You can probably get around this by using your machine local IP address (typically 192.168.XXX.XXX not 127.0.0.1) if both the device and machine is connected to the same network. 如果设备和计算机都连接到同一网络,则可以使用计算机的本地IP地址(通常为192.168.XXX.XXX而不是127.0.0.1)来解决此问题。

这对我来说很好用http://10.0.2.2/yourfilepath 。我认为您需要这个。此外,您可以使用JSON在android应用程序中操作数据,我在代码中使用了这种方式。

我经历了完全相同的问题,我使用ip地址而不是localhost127.0.0.1解决了它。

The localhost refers to the device on which the code is running, in this case the emulator. 本地主机是指在其上运行代码的设备,在本例中为仿真器。

If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead. 如果要引用运行Android模拟器的计算机,请改用IP地址10.0.2.2。 You can read more from here. 您可以从这里阅读更多内容。

this link might be helpful : https://stackoverflow.com/a/5806384/3510202 这个链接可能有帮助: https : //stackoverflow.com/a/5806384/3510202

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

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