mamp - PHP/MySQL – Error when connecting to server -


i'm using mac osx , have mamp installed, running localhost server. however, there issues running php code because website keeps returning there error when connecting server. don't know what's wrong this; maybe can me out here.

php code:

<?php  $connection = mysql_connect("localhost", "user", "password") or die ("there error when connecting server"); mysql_select_db("topaz", $connection) or die ("there error when connecting database");  echo "    <body style='font-family: helvetica neue, helvetica, arial, sans-serif;'>      <div style='width: 80%; padding: 10px; border: 1px solid #000000; background-color: #ffffff;'>       <h1>login</h1>     </div>    </body> ";  ?> 

phpmyadmin settings: enter image description here

mamp port settings: enter image description here

error: enter image description here

you need establish connection on port specified in control panel - default, mysql_connect() attempt connect mysql host on port 3306.

specify port use in first parameter (host) of mysql_connect:

$connection = mysql_connect("localhost:8889", "user", "password") or die ("there error when connecting server"); //                               here ^^^^^ 

mandatory note: don't use mysql_* functions they're deprecated. use pdo or mysqli_* instead.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -