0

the connection to database via PHP is as:

<?php
$DbHost = 'localhost';
$DbName = 'root';
$DbUser = 'root';
$DbPwd = '';
$dbConn = mysql_connect ($DbHost, $DbUser, $DbPwd) 
    or die ('MySQL connect failed. ' .mysql_error());
mysql_select_db($DbName,$dbConn) or die('Cannot select database. ' . mysql_error());
?>

Here I've hardcoded my hostname, username and password. Everytime I take my project to another machine, I've to change it. How can I make this connection code dynamic?

4

1 回答 1

0

您可以将机器特定信息放在settings.php文件中并使用

require_once "settings.php";

获取机器设置。在您的所有机器上执行此操作并将文件放在特定位置,以便您的项目能够找到它。

当您将项目移动到另一台机器时,它将使用相应的settings.php文件。(假设您也没有复制此文件;))

于 2013-01-14T11:47:45.567 回答