php開發(fā)留言板之?dāng)?shù)據(jù)庫文件配置
連接數(shù)據(jù)庫
編寫思路
新建文件conn.php? 用來設(shè)置連接數(shù)據(jù)庫文件
<?php $conn =mysql_connect("localhost", "root", "123456789") or die("數(shù)據(jù)庫鏈接錯(cuò)誤"); mysql_select_db("bbs", $conn); mysql_query("set names 'utf8'"); //使用utf-8中文編碼; ?>
root填寫mysql的用戶名? 123456789可填自己的數(shù)據(jù)庫密碼
or die("數(shù)據(jù)庫鏈接錯(cuò)誤");做判斷
mysql_select_db("bbs", $conn);
bbs的位置填寫自己數(shù)據(jù)庫中表的名稱
后面的文件 需要用到數(shù)據(jù)庫連接,只需要調(diào)用conn.php文件就可以將使用,很方便。