基本上我要做的是将数据库访问变量(用户名、密码等)重新定位到外部 php 文件,然后将该文件包含在服务中。因此,这是我可以使用的服务代码:
<?php
/** Database Access Information */
class LoginService {
require 'parameters.php';
var $accesstable = "access";
var $lastlogintable = "last_login";
var $loginhistorytable = "login_history";
var $connection;
/** The constructor initializes the connection to database. */
public function __construct() {
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename,
$this->port
);
$this->throwExceptionOnError($this->connection);
}
然后这是我认为可以在外部文件中使用的代码:
<?php
var $username = "root";
var $password = "";
var $server = "localhost";
var $port = "3306";
var $databasename = "User";
?>
但是,唉,它没有用...... Dreamweaver 一直在给我一个语法错误:
require 'parameters.php';