如何使用PHP连接到在线MySQL数据库? [英] How do I connect to an online MySQL database using PHP?

查看:79
本文介绍了如何使用PHP连接到在线MySQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XAMPP离线测试网站.我的PHP代码连接到我的本地MySQL数据库并与之一起工作(即'localhost'或'127.0.0.1').我希望使用在线MySQL数据库进行测试. 我正在尝试使用PHPMyAdmin 演示服务器,但是尝试连接服务器时出现错误.我将"DB_HOST"更改为"192.168.30.23"(这似乎是演示服务器的IP地址).我想念什么吗?

I am testing a website offline with XAMPP. My PHP code connects and works with my local MySQL database (i.e. 'localhost' or '127.0.0.1'). I wish to conduct tests using an online MySQL database. I am trying to use PHPMyAdmin Demo Server but I get an error when trying to connect to the server. I changed the 'DB_HOST' to '192.168.30.23' (which seems to be the demo server ip address). Am I missing something?

这是我的代码段:

<?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());
}

?>

谢谢.

推荐答案

phpMyAdmin MySQL演示服务器无法测试您的脚本.谷歌为公共访问MySQL服务器"找到了一个.

The phpMyAdmin MySQL demo server is not available to test your script. Google for "public access MySQL server" to maybe find one.

这篇关于如何使用PHP连接到在线MySQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆