php 如何在 WAMP 服务器上连接到 MySQL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2459006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:33:49  来源:igfitidea点击:

How can I connect to MySQL on a WAMP server?

phpmysqlwamp

提问by Phrixus

This might be ridiculously easy for you but I've been struggling with this for an hour... :(

这对你来说可能非常容易,但我已经为此苦苦挣扎了一个小时...... :(

<?php
$connect = mysql_connect("localhost:8080", "root", "mypassword");
echo($connect);?>

This is the code that I'm trying to run - you can see that I'm using 8080 as my port number and, of course, I have HTML codes as well.

这是我要运行的代码 - 您可以看到我使用 8080 作为我的端口号,当然,我也有 HTML 代码。

However, it gives me the following error messages whenever I try to open the PHP file:

但是,每当我尝试打开 PHP 文件时,它都会给我以下错误消息:

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2

Warning: mysql_connect() [function.mysql-connect]: Error while reading greeting packet. PID=4932 in C:\wamp\www\php_sandbox\index.php on line 2

Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2

I don't know... what's wrong with this? Is it because of the port number?

我不知道……这有什么问题?是因为端口号吗?

回答by JonnyLitt

Change localhost:8080 to localhost:3306.

将 localhost:8080 更改为 localhost:3306。

回答by Kevin

Try opening Port 3306, and using that in the connection string not 8080.

尝试打开端口 3306,并在连接字符串中使用它而不是 8080。

回答by Snehasis Mohapatra

Just Change the Connection mysql string to 127.0.0.1 and it will work

只需将连接 mysql 字符串更改为 127.0.0.1 即可