mamp mysql 无法连接,无法使用MAMP或社区服务器连接到mysql服务器

I created a database with MySQL Workbench, and now I need to access it. So I've written a php script to access it:

$db = mysql_connect("127.0.0.1:3306","root", "");

if (!$db){

echo "Could not connect to database";

exit();

}

$db_name = "pfc_db";

if (!mysql_select_db($db_name, $db)){

die ("Could not select database");

}

$sql=mysql_query("select * from CAPAS");

while($row=mysql_fetch_assoc($sql)){

$output[]=$row;

if (isset($output)){

echo "yes";

echo $output[0];

}

else{echo "no";}

}

mysql_close();

?>

I have doubts about MAMP and MySQL Community Server and I need a push on the right path.

I've installed MAMP on my mac and switched the ports to the default mysql ones 3306. I've placed the PHP test script in a folder "Api" I've created under htdocs. So to try it out i type on my browser http://127.0.0.1/api/test.php and the result is "Could not connect to databse". Am I doing it right?

And what about Community Server? Is it better than MAMP? Should it be running for MAMP to work? Can I just use Community Server? If so, where should I place the PHP scripts? Which folder? Because when I try to do the same test with Community Server, instead of showing the error message, the browser starts downloading the php script to my downloads folder. Why happens that?

As you can see I have a bit of a mess in my mind with these server stuff and I need some help to figure it out.

解决方案

Well, I'm gonna answer myself so that if someone runs into the same problem.

The error of password happened because I had two installations of mysql in the same computer, so that I was checking the passwords in one of them and the browser was looking at the other.

Therefore, if you have problems with password access, check that you don't have two mysql installed and also check the file config.inc.php

I also changed TCP/IP by a socket connexion, which improves the speed if you're using your localhost as server.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值