php - 非常基本的连接到 mysql/测试问题

标签 php mysql dreamweaver

如果这是一个非常愚蠢的问题,我提前道歉(我是 php 和 mysql 的新手。

基本上,我正在设置 connect_to_mysql.php 文件, 如此处 (5:50) 所示: http://www.youtube.com/watch?v=YaII5QhNCH0

并且如下所示: http://www.developphp.com/view_lesson.php?v=248

我正在使用 MAMP。端口是 80/3306 但是我知道在 MAMP 起始页上它说,以下内容也不起作用。:

MySQL

可以使用 phpMyAdmin 管理 MySQL 数据库。

要从您自己的脚本连接到 MySQL 服务器,请使用以下连接参数:

主机:本地主机 端口:3306 用户:根 密码:root

这是我的:

这是 connect_to_mysql.php:

        <?php  
    // Created BY Adam Khoury @ www.flashbuilding.com - 6/19/2008  
/*  
1: "die()" will exit the script and show an error statement if something goes wrong with     the     "connect" or "select" functions. 
2: A "mysql_connect()" error usually means your username/password are wrong  
3: A "mysql_select_db()" error usually means the database does not exist. 
*/ 
// Place db host name. Sometimes "localhost" but  
// sometimes looks like this: >>      ???mysql??.someserver.net 
$db_host = "localhost"; 
// Place the username for the MySQL database here 
$db_username = "builder2";  
// Place the password for the MySQL database here 
$db_pass = "builder2";  
// Place the name for the MySQL database here 
$db_name = "suitstore"; 

// Run the actual connection here  
mysql_connect("$localhost","$builder2","$builder2") or die ("could not connect to     mysql");
mysql_select_db("$suitstore") or die ("no database");              
?>

这是 test.php:

    <?php   
    // Connect to the file above here   
require "connect_to_mysql.php";  

echo "<h1>Success in database connection! Happy Coding!</h1>";   
// if no success the script would have died before this success message 
?>

因此,当我在 Chrome 上加载测试站点时,它显示: 服务器错误 该网站在检索 时遇到错误。它可能因维护而停机或配置不正确。 以下是一些建议: 稍后重新载入此网页。 HTTP 错误 500(内部服务器错误):服务器尝试完成请求时遇到意外情况。

所以,这可能是问题的一部分:在 DW 中,当我打开 test.php 时,它告诉我“此站点可能具有只能由服务器 [发现] [首选项] 发现的动态相关文件”

然后,如果我点击发现,它会说: “由于内部服务器错误,无法解析动态相关文件。[重试]”

谢谢,抱歉,如果这是一个愚蠢的问题。我真的不知道 jack 关于 php/mysql。

最佳答案

我认为他们应该是。

mysql_connect($db_host,$db_username,$db_pass) or die ("could not connect to mysql");
mysql_select_db($db_name) or die ("no database");   

关于php - 非常基本的连接到 mysql/测试问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13021477/

相关文章:

php - 将数据库中的坐标绘制到谷歌地图中,​​不断检查新值

php - 计算结束日期 : PostgreSQL 的年份

php - XSLT 使用正则表达式、单词边界搜索 XML

php - MySQL 选择时间戳在 X 时间之后的条目

MySQL 选择下一个较低的数字,但最多 10%

php - 比较sql中的时间戳和日期

php - 为什么 Json 无法识别 MySQL 计算值/列?

php - 是否可以在 Dreamweavers 动态表格向导中更改动态表格布局?

javascript - Dreamweaver JavaScript 调试器

javascript - Superfish HTML 和 CSS 不显示菜单