dreamy1992
dreamy1992
2013-08-08 08:46

PHP Mysql数据库类错误[关闭]

已采纳

I don't know why I am having this error. I'm using WampServer. I am trying to configure my database thru OOP and I came up with this error.

Parse error: syntax error, unexpected '?>', expecting function (T_FUNCTION)

 <?php
    Class Database{
        private $_host = null;
        private $_user = null;
        private $_pass = null;
        private $_db = null;
        var $con = false;

    public function connects($host, $user, $pass, $db){
        $this->_host = $host;
        $this->_user = $user;
        $this->_pass = $pass;
        $this->_db = $db;

        $this->con = mysql_connect($this->_host, $this->_user, $this->_pass);
        if(!$this->con){
            return false;
        }
        else{
            $sql = mysql_select_db($this->_db);
            if(!$sql){
                return false;
            }
            else{
                return true;
            }
        }
    } 
?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doushijiao0679 doushijiao0679 8年前

    You are missing

    }
    

    to finalize the class Database {

    To avoid this, use proper line indention and follow the Zend Coding Style Guide

    点赞 评论 复制链接分享