目前我已經使用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();
}
}
?>