mysqldatabasemampcommunity-server

Cannot connect to mysql server with MAMP nor with Community Server


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.


Solution

  • 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.