我的OOP代码问题 [英] Issue with my OOP codes

查看:79
本文介绍了我的OOP代码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解析错误:语法错误,第33行的C:\ xampp \htdocs \ OOP \ blog \libs \ database.php中的意外其他(T_ELSE)





我的尝试:



< pre lang =PHP> < pre > <? php


class 数据库{

public $ host = DB_HOST;
public $ user = DB_USER;
public $ pass = DB_PASS;
public $ db_name = DB_NAME;

public $ link ;

public function __construct(){
$ this-> connect();
}


私人函数connect(){
$ this - > link = new mysql ($这 - >主机,$这 - >用户,这 - $>通,$这 - > DB_NAME);



}

公共函数选择($查询){

$ result = $ this-> link - > query($ query);
if($ result-> num_rows> 0){
}
return $结果;


else {
return false;
}


}
公共函数插入($ query){

$ insert = $ this-> link-> query($ query);

if($ insert){
header(' location:index.php ?insert = Post inserted ...');
}
else {
echo 帖子没有插入......;
}

}

公共函数更新($查询){

$ update = $ this-> link-> query($ query);

if($ update){
header(' location:index.php ?更新=发布更新后......');
}
else {
echo 帖子没有更新......;
}

}

公共函数删除($ delete){

$ delete = $ this-> link-> query($ query);

if($ delete){
header(' location:index.php ?delete =发布已删除...');
}
else {
echo 帖子没有删除......;
}

}


}

?>

解决方案

host = DB_HOST;
public


user = DB_USER;
public


pass = DB_PASS;
public


Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\OOP\blog\libs\database.php on line 33



What I have tried:

<pre><?php


class database{

public $host = DB_HOST;
public $user = DB_USER;
public $pass = DB_PASS;
public $db_name = DB_NAME;

 public $link;

public function __construct(){
	$this->connect();
}


 private function connect(){
$this ->link=new mysql ($this->host,$this->user,$this->pass,$this->db_name);



 }

public function select($query){

$result = $this->link ->query($query);
if($result->num_rows> 0){
}
return $result;


else{
	return false;
}


}
public function insert($query){

$insert = $this->link->query($query);

if($insert){
	header('location:index.php?insert= Post inserted ...');
}
else{
	echo"Post did not insert ...";
}

}

public function update($query){

$update = $this->link->query($query);

if($update){
	header('location:index.php?Update= Post updated  ...');
}
else{
	echo"Post did not update ...";
}

}

public function delete($delete){

$delete = $this->link->query($query);

if($delete){
	header('location:index.php?delete= Post deleted ...');
}
else{
	echo"Post did not delete ...";
}

}


}

?>

解决方案

host = DB_HOST; public


user = DB_USER; public


pass = DB_PASS; public


这篇关于我的OOP代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆