php面向?qū)ο笪募鸇B.class.php

成都創(chuàng)新互聯(lián)公司是專業(yè)的中江網(wǎng)站建設公司,中江接單;提供成都做網(wǎng)站、成都網(wǎng)站設計,網(wǎng)頁設計,網(wǎng)站設計,建網(wǎng)站,PHP網(wǎng)站建設等專業(yè)做網(wǎng)站服務;采用PHP框架,可快速的進行中江網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
?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ù)庫賬號密碼等信息變更了,那么只需要修改下面兩個配置文件下對應的數(shù)據(jù)庫連接信息:
caches/configs/databses.php
phpsso_server/caches/configs/databases.php
相關(guān)配置項說明如下:
return array (
'default' = array (
'hostname' = 'localhost', //數(shù)據(jù)庫服務器ip地址,本機用localhost即可
'port' = 3306,
'database' = 'rzdxs_db', //數(shù)據(jù)庫名
'username' = 'root', //賬號
'password' = '123456', //密碼
'tablepre' = 'dxs_', //表前綴
'charset' = 'utf8',
'type' = 'mysqli',
'debug' = true,
'pconnect' = 0,
'autoconnect' = 0
),
);
二、
如果搬家后域名也變更了,那么除了以上兩個文件,就需要多修改一下兩個配置文件:
caches/configs/system.php
phpsso_server/caches/configs/system.php
以上兩個文件主要修改對應的變更后的域名配置,另外,注意,將數(shù)據(jù)庫所有數(shù)據(jù)導出為sql文件,使用編輯器批量替換更能將里面所有域名替換為新域名。
PS:以前回答的相關(guān)類似問題可參考:
還可以參考官方說明以及iphpcms的教程。
thinkphp\common文件夾中的convention.php中是tp的核心配置文件,不能亂動,如果要想更改里面的配置,在conf
文件夾里面的config.php可以配置,可以這樣寫
?php
return
array(
'db_type'
=
'mysql',//
數(shù)據(jù)庫類型
'db_host'
=
'127.0.0.1',//
數(shù)據(jù)庫服務器地址
'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
本文標題:php設置數(shù)據(jù)庫配置文件,php如何配置
網(wǎng)頁網(wǎng)址:http://chinadenli.net/article29/dsissjh.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化、移動網(wǎng)站建設、外貿(mào)建站、網(wǎng)站改版、網(wǎng)站營銷、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)