重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
'DB_TYPE' = 'mysql',// 數(shù)據(jù)庫類型
為紅河等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及紅河網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都做網(wǎng)站、成都網(wǎng)站制作、紅河網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
'DB_HOST' = '127.0.0.1',// 數(shù)據(jù)庫服務(wù)器址
'DB_NAME' = 'thinkphp',// 數(shù)據(jù)庫名稱
'DB_USER' = 'root',// 數(shù)據(jù)庫用戶名
'DB_PWD' = '123',// 數(shù)據(jù)庫密碼
'DB_PREFIX' = 'tp_',// 數(shù)據(jù)表前綴
'DB_CHARSET' = 'utf8',// 網(wǎng)站編碼
'DB_PORT' = '3306',// 數(shù)據(jù)庫端口
'APP_DEBUG' = false,// 啟調(diào)試模式
php面向?qū)ο笪募鸇B.class.php
?php
header("content-type:text/html;charset=utf-8");
class?DB{
?public?$db_host;//localhost
?public?$db_user;//用戶名
?public?$db_pwd;//密碼
?public?$db_name;//數(shù)據(jù)庫名
?public?$links;//鏈接名稱
?//構(gòu)造方法的參數(shù)和屬性名字一致,但是含義不同
?function?__construct($db_host,$db_user,$db_pwd,$db_name){
?$this?-?db_host?=?db_host;
?$this?-?db_user?=?db_user;
?$this?-?db_pwd?=?db_pwd;
?$this?-?db_name?=?db_name;
?//鏈接數(shù)據(jù)庫代碼
?$this?-?links?=?@mysql_connect($db_host,$db_user,$db_pwd)or?die("數(shù)據(jù)庫鏈接失敗");
?//echo?$this?-?links;打印是資源
?mysql_query("set?names?utf8");
?mysql_select_db($db_name,$this-links);
?
?}
?function?query($sql){//執(zhí)行各種sql,inert?update?delete執(zhí)行,如果執(zhí)行select返回結(jié)果集
?return?mysql_query($sql);
?}
?function?numRows($sql){//返回select的記錄數(shù)
?$result?=?$this?-?query($sql);
?$count?=?mysql_num_rows($result);
?return?$count;
?}
?function?getOne($sql){//得到一條記錄的一維數(shù)組
?$result?=?$this?-?query($sql);
?$arr?=?mysql_fetch_assoc($result);
?return?$arr;
?}
?function?getAll($sql){//得到多條記錄的二維數(shù)組
?$result?=?$this?-?query($sql);
?$rows?=?array();
?while($rs?=?mysql_fetch_assoc($result)){
?$rows[]?=?$rs;
?}
?return?$rows;
?}
?function?__destruct(){
?$this?-?db_host?=?db_host;
?$this?-?db_user?=?db_user;
?$this?-?db_pwd?=?db_pwd;
?$this?-?db_name?=?db_name;
?}
?}
?
?$db?=?new?DB("localhost","root","","car");
?//$sql?=?"insert?into?category(categoryName)values('常熟seo')";
?//$db?-?query($sql);
?
?//返回select的記錄數(shù)
?//$sql?=?"select?*?from?category";
?//$count?=?$db?-?numRows($sql);
?//echo?$count;
?
?//得到一條記錄的一維數(shù)組
?//$sql?=?"select?*?from?category?where?categoryId=1";
?//$arr?=?$db?-?getOne($sql);
?//print_r($arr);
?
?//得到多條記錄的二維數(shù)組
?$sql?=?"select?*?from?category";
?$rs?=?$db?-?getAll($sql);
?print_r($rs);
?
?
?
創(chuàng)建一個數(shù)據(jù)庫大類
正確找到phpcms數(shù)據(jù)庫配置文件的步驟如下(有兩個文件需要更改):
1.根目錄文件夾/caches/configs/database.php;
2.根目錄文件夾/phpsso_server/caches/configs/database.php
$host='localhost';
$user='root';
$pass='123456';
$db='edu';
$conn=@mysql_connect($host,$user,$pass);
if(!$conn){
die('Could not connect: ' . mysql_error());
}
else{
mysql_select_db($db,$conn);
}
我是這樣寫得和你的第二種貌似
thinkphp\common文件夾中的convention.php中是tp的核心配置文件,不能亂動,如果要想更改里面的配置,在conf
文件夾里面的config.php可以配置,可以這樣寫
?php
return
array(
'db_type'
=
'mysql',//
數(shù)據(jù)庫類型
'db_host'
=
'127.0.0.1',//
數(shù)據(jù)庫服務(wù)器地址
'db_name'
=
'thinkphp',//
數(shù)據(jù)庫名稱
'db_user'
=
'root',//
數(shù)據(jù)庫用戶名
'db_pwd'
=
'123',//
數(shù)據(jù)庫密碼
'db_prefix'
=
'tp_',//
數(shù)據(jù)表前綴
'db_charset'
=
'utf8',//
網(wǎng)站編碼
'db_port'
=
'3306',//
數(shù)據(jù)庫端口
'app_debug'
=
false,//
開啟調(diào)試模式
);
?
也可以在最外邊寫,就是與thinkphp框架同一目錄中寫一個config.php文件,格式如同上面的一樣,不過在conf
文件夾里面的config.php中得包含最外邊的那個config.php