我无法连接我的数据库。 PHP和MySQL

时间:2017-11-27 18:29:27

标签: php mysql database wamp

我只是PHP的初学者。我无法连接我的数据库。这是我的代码:

<?php
require 'config.php';

class db_class {
    public $host        =db_host;
    public $username    =db_username;
    public $password    =db_password;
    public $db_name =db_name;
    public $conn;
    public $error;

    private function _construct () 
    {
        $this-> conn (); 
    }

    private function connect () {
        $this->conn=new mysqli ($this->host, $this->username, $this->password, $this->db_name);
        if ($this->conn) {
            $this-> error ="Fatal Error: Can't connect to lib database" .$this->conn->connect_error;
        return false;
        }
    }

    public function save ($username, $password, $first_name, $middle_name, $last_name, $student_id) 
    {
        $reg = $this->conn->prepare ("INSERT INTO registration (username, password, first_name, middle_name, last_name, student_id) VALUES (?, ?, ?, ?, ?, ?)") or die ($this->conn->error);
        $reg->bind_param ("sssss",$username,$password,$first_name,$middle_name,$last_name, $student_id);
        if  ( $reg->execute()) {
            $reg->close();
            $this->conn->close();
            return true;
        }
    }
}
?>

所以,当我点击“提交”按钮时,没有任何反应。请帮忙。谢谢!

0 个答案:

没有答案