PHP Simple MySQL Database Manager
Hi Everyone! I just finished making the first version of my personal MySQL Database Manager in PHP.
Hope you all like it.
class MySQL_Server function __construct($user, $password, $host, $db, $table) private function connect_database() public function get_all_data() public function insert_data($title, $description, $deadline) public function update_data($id, $newTitle, $newDescription, $newDeadline) public function delete_data($id) } ?>
<?php
{
private $user;
private $password;
private $host;
private $db;
private $table;
private $cnt;
{
$this->user = $user;
$this->password = $password;
$this->host = $host;
$this->db = $db;
$this->table = $table;
$this->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);
}
{
$sql = "SELECT * FROM $this->table";
return $this->cnt->query($sql);
}
{
$date = date("Y-m-d");
$sql = "INSERT INTO $this->table
(title, description, created_at, deadline)
VALUES ('$title', '$description', '$date', '$deadline')";
$this->cnt->exec($sql);
}
{
$sql = "UPDATE $this->table SET title=$newTitle WHERE id=$id";
$this->cnt->exec($sql);
}
{
$sql = "DELETE FROM $this->table WHERE id='$id'";
$this->cnt->exec($sql);
}
Congratulations @fleira98! You received a personal award!
Click here to view your Board of Honor
Congratulations @fleira98! You received a personal award!
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!