MySQL issue connecting to site with php

2019-08-25 23:51发布

问题:

Every time I try to connect to my localhost (using MAMP), it tells me that either access was denied or that it can't connect!!! It is driving me crazy! I have the php example below. What am I missing, because apparently nobody on the web is having this same problem...

//setup db connection

$link = mysqli_connect("localhost","root","");
mysqli_select_db($link, "iReport")

回答1:

Try...

//Database Information

$dbhost = "serverip";
$dbname = "databasename";
$dbuser = "username";
$dbpass = "password";


//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());