Home  >  Article  >  Backend Development  >  新手关于$coon的连接有关问题

新手关于$coon的连接有关问题

WBOY
WBOYOriginal
2016-06-13 12:04:20877browse

新手关于$coon的连接问题
 对于数据库连接,我发现有两种,第一种是:
$db_host='localhost';??//数据库主机名称
$db_user='root';? ?? ???//数据库用户帐号
$db_passw='123';? ?//数据库用户密码
$db_name='list';? ?? ?? ?//数据库具体
$conn = mysql_connect($db_host,$db_user,$db_passw) or die ('数据库连接失败!');

第二种是:
$conn = mysql_connect(localhost,root,123) or die ('数据库连接失败!');

明显第二种比第一种要方便很多,为什么有的人喜欢用第一种呢,是不是还有什么其他用途。
------解决方案--------------------
并不存在两种方法!
谨慎的人不大愿意让别人看到口令,所以使用了变量
当然真正的代码中,这些变量是放在你看不到的地方的
------解决方案--------------------
还有一种解释就是,变量可以放在一个单独的配置文件中,然后include进来,这样方便以后管理。
------解决方案--------------------
不用那么纠结,就是习惯而已

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn