简体   繁体   English

如何使用PHP连接到在线MySQL数据库?

[英]How do I connect to an online MySQL database using PHP?

I am testing a website offline with XAMPP. 我正在使用XAMPP离线测试网站。 My PHP code connects and works with my local MySQL database (ie 'localhost' or '127.0.0.1'). 我的PHP代码连接并与我的本地MySQL数据库(即“ localhost”或“ 127.0.0.1”)一起使用。 I wish to conduct tests using an online MySQL database. 我希望使用在线MySQL数据库进行测试。 I am trying to use PHPMyAdmin Demo Server but I get an error when trying to connect to the server. 我正在尝试使用PHPMyAdmin 演示服务器,但是尝试连接到服务器时出现错误。 I changed the 'DB_HOST' to '192.168.30.23' (which seems to be the demo server ip address). 我将“ DB_HOST”更改为“ 192.168.30.23”(这似乎是演示服务器的IP地址)。 Am I missing something? 我想念什么吗?

Here is a snippet of my code: 这是我的代码片段:

<?php

define('DB_NAME', 'ears');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', '192.168.30.23');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

?>

Thank you in advance. 先感谢您。

The phpMyAdmin MySQL demo server is not available to test your script. phpMyAdmin MySQL演示服务器无法测试您的脚本。 Google for "public access MySQL server" to maybe find one. 谷歌为“公共访问MySQL服务器”找到了一个。

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

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