database=$database; } if"/> database=$database; } if">
Home > Backend Development > PHP Tutorial > 求教,新手学习数据库操作类,多谢

求教,新手学习数据库操作类,多谢

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:50:56
Original
923 people have browsed it

求教,新手学习数据库操作类,谢谢
代码如下,一个数据库操作类里面的一个方法
public function select_db($database="") {
// 选择数据库
if ($database!="") {
$this->database=$database;
}

if(!mysql_select_db($this->database, $this->link_id)) {
$this->halt("无法使用数据库 ".$this->database);
}
}


我的问题是:
1.下面的代码里面的$database=""是什么意思?不是参数传递吗?为什么要赋值空字符串?
2.if ($database!="") {
$this->database=$database;
}是什么意思?里面的$this->database和$database是2个不同的变量吗?为什么名字一样?

------解决方案--------------------
1.$database=""表示$database定义一个默认值(空字符) 如果你调用这个函数没有传参数那么这个$database就是个空字符
2.$this->database是这个类的一个属性 而$database只是一个变量(传递过来的值)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Database file import
From 1970-01-01 08:00:00
0
0
0
database
From 1970-01-01 08:00:00
0
0
0
Database design - mysql database integration
From 1970-01-01 08:00:00
0
0
0
Database garbled,
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template