Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a3afb01

Browse files
案例blog,拿取数据库网站配置信息
1 parent 46d7fad commit a3afb01

File tree

4 files changed

+113
-86
lines changed

4 files changed

+113
-86
lines changed

‎.idea/workspace.xml‎

Lines changed: 88 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎php-mysql/blog/class/conn.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function GetConn(){ // 连接数据库
2424
mysqli_query($this->conn,"set names 'utf-8'");//设置数据库的编码格式
2525
return $this->conn; //返回连接对象
2626
}
27-
function CloseConn9(){ //定义关闭数据库的方法
27+
function CloseConn(){ //定义关闭数据库的方法
2828
mysqli_close($this->conn);
2929
}
3030
}

‎php-mysql/blog/class/system.php‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,36 @@
1010
class SystemInfo{
1111
var $site_name; //站点名称
1212
var $site_owner; //站点作者
13-
function get_info(){
13+
function get_name(){
1414
$sys_conn = new ConnDB();
15-
$sys_conn->conn_db('localhost','root','','system_config');
15+
$sys_conn->conn_db('localhost','root','','blog');
1616
$conn = $sys_conn->GetConn();
17-
$this->site_name = mysqli_query($conn,"select blog_title from system_config");
18-
$this->site_owner = mysqli_query($conn,"select blog_hoster from system_config");
19-
17+
$sql= mysqli_query($conn,"select blog_title from system_config");
18+
$info = mysqli_fetch_array($sql); //获取查询结果
19+
$this->site_name = $info['blog_title'];
20+
$sys_conn->CloseConn();
21+
}
22+
function get_owner(){
23+
$sys_conn = new ConnDB();
24+
$sys_conn->conn_db('localhost','root','','blog');
25+
$conn = $sys_conn->GetConn();
26+
$sql1 = mysqli_query($conn,"select blog_hoster from system_config");
27+
$info1 = mysqli_fetch_array($sql1); //获取查询结果
28+
$this->site_owner = $info1['blog_hoster'];
29+
$sys_conn->CloseConn();
2030
}
2131
function SetInfo(){
2232
if($this->site_name == ''){
23-
$this->site_name = 'site_name';
24-
}
25-
26-
if($this->site_name == ''){
27-
$this->site_owner = 'site_hoster';
33+
$this->site_name = '小小梦工场的网站';
2834
}
2935
define('SITE_NAME',$this->site_name,TRUE);
36+
if($this->site_owner == ''){
37+
$this->site_owner = '小小梦工场';
38+
}
3039
define('SITE_OWNER',$this->site_owner,TRUE);
3140
}
3241
}
3342
$system_info = new SystemInfo();
34-
$system_info->get_info();
35-
$system_info->get_info();
43+
$system_info->get_name();
44+
$system_info->get_owner();
45+
$system_info->SetInfo();

‎php-mysql/blog/index.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Date: 2016年10月31日
66
* Time: 23:01
77
*/
8+
require 'class/system.php';
89
//主页
9-
echo SITE_NAME;
10+
echo SITE_NAME.'<br>';
1011
echo SITE_OWNER;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /