学生表包含: id firstname lastname
函数 get_db_fields 获取学生表字段。
class Student{
public function get_db_fields(){
$sql = "SELECT * FROM students";
$result = mysql_query($sql);
if(!$result){
die("Failed :" . mysql_error());
}
$db_fields = array();
while($field = mysql_fetch_field($result)){
$db_fields[] = "'".$field->name."'";
}
return join(',',$db_fields);
}
public $db_fields = array($this->get_db_fields()); <--- This is not working
}
return join(',',$db_fields) = 'id','firstname','lastname'
我的问题是如何将返回值设置为 public $db_fields。所以 public $db_fields 将是 "public $db_fields = array('id','firstname','lastname')"
到目前为止我尝试过的
1.)
public $db_fields = array($this->get_db_fields()); <--- This is not working
错误:解析错误:语法错误,第 33 行 C:\Program Files\xampp\htdocs\ieti\includes\student.php 中的意外 T_VARIABLE
2.) $database_fields = $this->get_db_fields();
错误:解析错误:语法错误,第 33 行 C:\Program Files\xampp\htdocs\ieti\includes\student.php 中的意外 T_VARIABLE