嗯,我明白为什么会有这个错误:
Parse error: syntax error, unexpected '$alert' (T_VARIABLE) in C:\wamp\www\envMailAuto\controler.php on line 19
我的控制器:
include 'modele.php';
$email=$_REQUEST["email2"];
if(isset($_REQUEST["check"])) echo $email;
else echo "omged";
$idarticle = 3555;
$DB_host = "localhost";
$DB_select = "envmail";
$DB_login = "root";
$DB_pass = '';
$connection=mysql_connect($DB_host,$DB_login,$DB_pass);
$db=mysql_select_db($DB_select, $conn);
alertarticleDAO $alert = new __alertarticle($connection);
我的模特:
Class alertarticleDAO {
var $connection;
public function __alertarticle($mysqlconnection){
$this->connection = $mysqlconnection;
}
public function insert($Idarticle,$email){
$query=" INSERT INTO envmail ( mail_env , id_article , actif )
VALUES ( $Idarticle , $email , 1)";
mysql_query($query,$this->connection);
}
}
答案 0 :(得分:1)
只需删除无效关键字alertarticleDAO
即可。在PHP中,您不会像那样“设置”变量的类型。
但是你的“构造函数”并不完全正确,要么将其命名为类名,要么将其命名为__construct()
。
因此,您的构造函数应如下所示:
function __construct($mysqlconnection) { ... }
Instanciate it:
$alert = new alertarticleDAO($connection);
答案 1 :(得分:1)
在PHP中,初始化对象时无需指定类型。改变这一行:
alertarticleDAO $alert = new __alertarticle($connection);
进入这个:
$alert = new alertarticle($connection);
并且构造函数定义也是错误的,请更改:
public function __alertarticle($mysqlconnection){
进入这个:
function __construct($mysqlconnection){