PHP Simple MySQL Database Manager

in #technology7 years ago

Hi Everyone! I just finished making the first version of my personal MySQL Database Manager in PHP.

Hope you all like it.

<?php

class MySQL_Server
{
private $user;
private $password;
private $host;
private $db;
private $table;
private $cnt;

function __construct($user, $password, $host, $db, $table)
{
$this->user = $user;
$this->password = $password;
$this->host = $host;
$this->db = $db;
$this->table = $table;
$this->connect_database();
}

private function connect_database()
{
# Check if database server is up
try {
$this->cnt = new PDO(
"mysql:host=$this->host;dbname=$this->db;charset=utf8mb4",
$this->user,
$this->password);
$this->cnt = null;
} catch (PDOExeption $err) {
print "There is a problem with the server: " . $err . "
";
die();
}
$this->cnt = new PDO(
"mysql:host=$this->host;dbname=$this->db;charset=utf8mb4",
$this->user,
$this->password);
}

public function get_all_data()
{
$sql = "SELECT * FROM $this->table";
return $this->cnt->query($sql);
}

public function insert_data($title, $description, $deadline)
{
$date = date("Y-m-d");
$sql = "INSERT INTO $this->table
(title, description, created_at, deadline)
VALUES ('$title', '$description', '$date', '$deadline')";
$this->cnt->exec($sql);
}

public function update_data($id, $newTitle, $newDescription, $newDeadline)
{
$sql = "UPDATE $this->table SET title=$newTitle WHERE id=$id";
$this->cnt->exec($sql);
}

public function delete_data($id)
{
$sql = "DELETE FROM $this->table WHERE id='$id'";
$this->cnt->exec($sql);
}

}

?>

Sort:  

Congratulations @fleira98! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @fleira98! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.28
TRX 0.24
JST 0.041
BTC 94527.30
ETH 3297.48
USDT 1.00
SBD 7.84