0

here is the code that I am using:

$dbhost = "localhost:8080";
$dbuser = "root";
$dbpass = "";
$dbname = "test";

$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

    if(! $conn){
        die('Could not connect:'. mysql_error());
    }

    else{
        echo "Connected Successfully";
    }

    ?> 

when I use include or require_once, I never get the echo "Connected successfully" I always receive the error. This is for a university project, and in uni the windows computers connect right away, using the same code. since i am using MacOSX is there anything i need to do? My server is also running on bitnami MAMP

Mint
  • 1
  • Also, forgot to mention that I keep getting an HTTP error 500 – Mint Nov 20 '19 at 15:04
  • Please also show the detail of the error you received. The detailed message should give you some hint regarding the error. – nanangarsyad Nov 20 '19 at 15:04
  • Are you sure that 8080 is the correct port for your MySQL? The MAMP default is 8889 I believe. – Patrick Q Nov 20 '19 at 15:07
  • Just try it with localhost:8889 . In case it doesn't work, try to show up the errors using the solution there: https://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings And afterward, you will see the error message, which can help you to solve your problem. – Ilkin Alibayli Nov 20 '19 at 15:11
  • 3
    Also, instead of `mysql_error()`, you should be using [`mysqli_connect_error()`](https://www.php.net/manual/en/mysqli.connect-error.php) – Patrick Q Nov 20 '19 at 15:16
  • my port is definitely 8080 – Mint Nov 20 '19 at 15:37
  • the only error im getting right now is the HTTP 500 error so i don't know if its connecting now – Mint Nov 20 '19 at 15:38
  • is there any way to fix the HTTP 500 error? – Mint Nov 20 '19 at 15:57
  • 1
    You have to check your error logs to find the exact error message. – Patrick Q Nov 20 '19 at 16:03
  • By the way, even if you did use a custom port number, you’d include that as a fifth parameter to `mysqli_connect`, not burying it in the host name parameter. – Rob Nov 20 '19 at 16:36
  • “my port is definitely 8080” ... Don’t conflate your web server’s port (which conceivably might be 8080) and your database port (e.g. MySQL generally uses 3306). But 8080 is a well-known web server port number. Regardless, your 500 status code is likely unrelated to any error related to connecting MySQL error; it generally suggests a more fundamental PHP error. Is the above your full PHP? I notice that your `` is missing and wonder what else might have been excluded for brevity. – Rob Nov 20 '19 at 16:42
  • See [these](https://www.php.net/manual/en/mysqli.construct.php#121002) [two](https://www.php.net/manual/en/mysqli.construct.php#112328) comments regarding using "localhost" with custom ports. – Patrick Q Nov 20 '19 at 16:45
  • right, so I've done it! it was a problem with the port, I uninstalled MAMP and instead used XAMPP (my classmate recommended it), within my code for the $dbhost instead of including the port I didn't and now it connects – Mint Nov 20 '19 at 17:21
  • than you all for your support and help! this is my first time using stack overflow – Mint Nov 20 '19 at 17:21

0 Answers0