Fix: tdd for connect_db.php
This commit is contained in:
@@ -15,7 +15,7 @@ class DBConnector
|
||||
{
|
||||
global $db_host, $db_user, $db_passwd, $db_name;
|
||||
|
||||
if (isset($db_host) && $db_host !== null ) {
|
||||
if (isset($db_host) && $db_host !== null) {
|
||||
// echo "db_host variable\n";
|
||||
$this->db_host = $db_host;
|
||||
$this->db_user = $db_user;
|
||||
@@ -28,14 +28,10 @@ class DBConnector
|
||||
$this->db_passwd = "sEobMPuJ2A8KTfwU";
|
||||
$this->db_name = "chocomae";
|
||||
}
|
||||
$this->printDBVariables();
|
||||
|
||||
$this->connectDB();
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
$this->closeDB();
|
||||
}
|
||||
|
||||
public function connectDB()
|
||||
@@ -43,30 +39,36 @@ class DBConnector
|
||||
// connect db
|
||||
$this->db_conn = new mysqli($this->db_host, $this->db_user, $this->db_passwd, $this->db_name);
|
||||
if ($this->db_conn->connect_error) {
|
||||
// set_error_message("Failed to connect DB: ".$this->db_conn->connect_error);
|
||||
// send_result_fail();
|
||||
echo "connection failed\n";
|
||||
exit;
|
||||
} else {
|
||||
echo "connection succeeded\n";
|
||||
$query = "USE chocomae";
|
||||
$result = mysqli_query($this->db_conn, $query);
|
||||
return false;
|
||||
}
|
||||
|
||||
$query = "USE chocomae";
|
||||
$result = mysqli_query($this->db_conn, $query);
|
||||
if (!$result)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function closeDB()
|
||||
{
|
||||
if (isset($this->db_conn) || $this->db_conn === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->db_conn->connect_error) {
|
||||
$this->db_conn->close();
|
||||
}
|
||||
}
|
||||
|
||||
private function printDBVariables()
|
||||
public function getDBVariables()
|
||||
{
|
||||
echo "host : ".$this->db_host."\n";
|
||||
echo "user : ".$this->db_user."\n";
|
||||
echo "passwd : ".$this->db_passwd."\n";
|
||||
echo "name : ".$this->db_name."\n";
|
||||
$variables = array();
|
||||
$variables["host"] = $this->db_host;
|
||||
$variables["user"] = $this->db_user;
|
||||
$variables["passwd"] = $this->db_passwd;
|
||||
$variables["name"] = $this->db_name;
|
||||
return $variables;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user