我只是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;
}
}
}
?>
所以,当我点击“提交”按钮时,没有任何反应。请帮忙。谢谢!