新聞中心
php連接 mysql 數(shù)據(jù)庫如何添加一個公共的配置文件
php面向?qū)ο笪募鸇B.class.php
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名與空間、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、肅寧網(wǎng)站維護(hù)、網(wǎng)站推廣。
?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網(wǎng)站搬家遷移后怎樣修改數(shù)據(jù)庫配置文件
你好,phpcms搬家后分兩種情況來給你說名配置修改:
一、
如果只是數(shù)據(jù)庫賬號密碼等信息變更了,那么只需要修改下面兩個配置文件下對應(yīng)的數(shù)據(jù)庫連接信息:
caches/configs/databses.php
phpsso_server/caches/configs/databases.php
相關(guān)配置項說明如下:
return array (
'default' = array (
'hostname' = 'localhost', //數(shù)據(jù)庫服務(wù)器ip地址,本機(jī)用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
以上兩個文件主要修改對應(yīng)的變更后的域名配置,另外,注意,將數(shù)據(jù)庫所有數(shù)據(jù)導(dǎo)出為sql文件,使用編輯器批量替換更能將里面所有域名替換為新域名。
PS:以前回答的相關(guān)類似問題可參考:
還可以參考官方說明以及iphpcms的教程。
用php寫鏈接數(shù)據(jù)庫的配置文件,數(shù)據(jù)庫服務(wù)器為local host,用戶名root,密碼123456。 下面哪個正確?
$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);
}
我是這樣寫得和你的第二種貌似
網(wǎng)站數(shù)據(jù)庫如何修改 config.php文件的配置問題?
$db_host = "數(shù)據(jù)庫地址:3306";\x0d\x0a// database name\x0d\x0a$db_name = "數(shù)據(jù)表名";\x0d\x0a// database username\x0d\x0a$db_user = "數(shù)據(jù)庫用戶名";\x0d\x0a// database password\x0d\x0a$db_pass = "數(shù)據(jù)庫密碼";\x0d\x0a// table prefix\x0d\x0a將這上面的“數(shù)據(jù)庫地址”改為空間服務(wù)商給你的數(shù)據(jù)庫地址,將"數(shù)據(jù)表名"改為空間服務(wù)商給你的數(shù)據(jù)庫中的數(shù)據(jù)庫名稱,將"數(shù)據(jù)庫用戶名"改為空間服務(wù)商給你的數(shù)據(jù)庫的的賬戶名稱,將"數(shù)據(jù)庫密碼"改為空間服務(wù)商給你的數(shù)據(jù)庫的賬戶密碼。以上的數(shù)據(jù)只改“”里面的東西,“”不要去掉。然后將這個文件上傳到空間根目錄即可。
phpcms v9網(wǎng)站的數(shù)據(jù)庫配置文件在哪
正確找到phpcms數(shù)據(jù)庫配置文件的步驟如下(有兩個文件需要更改):
1.根目錄文件夾/caches/configs/database.php;
2.根目錄文件夾/phpsso_server/caches/configs/database.php
thinkphp配置數(shù)據(jù)庫文件在哪
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
網(wǎng)站欄目:php定義數(shù)據(jù)庫配置文件,php 文件數(shù)據(jù)庫
分享路徑:http://fisionsoft.com.cn/article/hdhjhh.html