目前我已经使用JavaScript来显示警报,以通知执行成功,仅用于测试目的。我怎样才能做到这一点在PHP面向对象的风格?如何在面向对象的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();
}
}
?>