0
votes

I'm working on a live site that db host is set to localhost. How is that possible?

define('DB_HOST','localhost');
define('DB_USER','user');
define('DB_PASS','password');
define('DB_TABL','system');
define('DB_PREFIX','pre_');

$conn = new PDO(
    'mysql:host='.DB_HOST.';dbname='.DB_TABL,
    DB_USER, 
    DB_PASS,
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") 
);
Because db is on same instance where web server is running from. That's why the for DB it's localhost. Please note that localhost is with respect to the server where it is residing not with respect to your machine :) - Imran Zahoor
localhost is not your computer. It is the IP of 127.0.0.0, so the machine it is running on, your server. - Markus Zeller
@MarkusZeller - it's 127.0.0.1 - Jay Buckman
@JayBuckman, You're right. Bad typo. - Markus Zeller