現在、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();
}
}
?>