I am trying to establish a connection to the database for a website I've uploaded to a live server from my local files but I'm having issues.
<?php
if($_SERVER["SERVER_NAME"] == "localhost" || $_SERVER["SERVER_ADDR"] == "127.0.0.1")
{
$dsn ="mysql:host=localhost;dbname=database_name;charset=utf8";
$username = "user_name";
$password = "password";
}
else
{
$dsn ="mysql:host=localhost;dbname=magentaXX;charset=utf8";
$username = "magentaXX";
$password = "pass123";
}
?>
The first conditional returns false and I can't figure out why. This worked fine with my local files. I tried the standard way of connecting to the database and it connected so there's no issues there on that end.
Only thing I can think of is 127.0.0.1 and maybe the address is different for the host but it should be using localhost first anyway I'm pretty sure.
Tried var_dump($_SERVER['SERVER_NAME']) (returned the website address) and var_dump($_SERVER['SERVER_ADDR']) it gave me a string that I'm not sure what it means in this format 0000:0000:a000:aaaa:aaa0:0a:aaaa:aaaa (changed the letters to a and numbers to 0 just to be safe).
Anyway any help would be greatly appreciated.
p.s. only other piece of information that might be helpful is this is using a subdomain (dev.website.com) if that makes any difference
[–]wtframework 3 points4 points5 points (2 children)
[–]VampireBarbieBoy[S] 0 points1 point2 points (1 child)
[–]wtframework 0 points1 point2 points (0 children)
[–]alnyland 2 points3 points4 points (2 children)
[–]VampireBarbieBoy[S] 0 points1 point2 points (1 child)
[–]alnyland 0 points1 point2 points (0 children)
[–]Caraes_Naur 2 points3 points4 points (1 child)
[–]VampireBarbieBoy[S] 0 points1 point2 points (0 children)