亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

PHP開發(fā)簡(jiǎn)易貼吧之連接數(shù)據(jù)庫(kù)函數(shù)

公共配置文件config.php

<?php
	header("Content-type:text/html;charset=utf-8");
	define('HOST','127.0.0.1');
	define('USERNAME','root');
	define('PASSWORD','root');
?>

程序解釋

  • 設(shè)置了文件的編碼格式

  • 將主機(jī)名,數(shù)據(jù)庫(kù)名,密碼定義成常量

公共連接數(shù)據(jù)庫(kù)文件connect.php

<?php 
require_once('config.php');
$conn = mysqli_connect(HOST,USERNAME,PASSWORD);//數(shù)據(jù)庫(kù)帳號(hào)密碼為安裝數(shù)據(jù)庫(kù)時(shí)設(shè)置
if(mysqli_errno($conn)){
echo mysqli_errno($conn);
exit;
}
mysqli_select_db($conn,"tieba");
mysqli_set_charset($conn,'utf8'); 
?>

程序解釋:

  • 引入了配置文件

  • 連接數(shù)據(jù)庫(kù),選擇tieba數(shù)據(jù)庫(kù),設(shè)置編碼格式為utf8

在后續(xù)的項(xiàng)目中,凡是要連接數(shù)據(jù)庫(kù)的地方,只需要引入connect.php文件即可。

繼續(xù)學(xué)習(xí)
||
<?php header("Content-type:text/html;charset=utf-8"); define('HOST','127.0.0.1'); define('USERNAME','root'); define('PASSWORD','root'); ?>
提交重置代碼