目前,我使用 JavaScript 显示警报以通知执行成功,仅用于测试目的。如何以 PHP 面向对象的风格做到这一点?
我试过了:
public $msg='May the force be with you.';
$this->msg = new msg();
...但结果是一个白色的空白页。我尝试过的 JavaScript 片段效果很好。下面是完整的代码:
<?php
class database {
public $mysql;
private $db_host='localhost';
private $db_username='admin';
private $db_password='password';
private $db_name='db';
function __construct() {
$this->mysql = new mysqli($this->db_host, $this->db_username, $this->db_password, $this->db_name) or die (mysql_error() ); {
echo
"<script type='text/javascript'>
alert ('The Force will be with you, always.');
</script>";
}
}
function __destruct() {
$this->mysql->close();
}
}
?>