我的OOP代码问题 [英] Issue with my OOP codes
问题描述
解析错误:语法错误,第33行的C:\ xampp \htdocs \ OOP \ blog \libs \ database.php中的意外其他(T_ELSE)
这篇关于我的OOP代码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我的尝试:
< 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