1

如果这是一个非常愚蠢的问题,我提前道歉(我是 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

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

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

主机:localhost 端口:3306 用户:root 密码: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 时,它告诉我“这个站点可能有动态相关的文件,只能由服务器 [Discover] [Preferences] 发现”

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

谢谢,对不起,如果这是一个愚蠢的问题。我真的不知道关于 php / mysql 的杰克。

4

1 回答 1

5

我认为他们应该是。

mysql_connect($db_host,$db_username,$db_pass) or die ("could not connect to mysql");
mysql_select_db($db_name) or die ("no database");   
于 2012-10-22T23:35:10.590 回答