/
golost
/
QaManagerBotBackend
Обзор
Документация
Войти
/
golost
/
QaManagerBotBackend
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
app1/api/objects/user.php
147 строк
4 KB
olegnizh
Добавьте файлы проекта.
05 июн 2024, 16:06
05 июн 2024, 16:06
8ef4523
Код
Авторство
О чём код?
<?php class Doctor{ // database connection and table name private $conn; private $table_name = "users"; // object properties public $id; public $name; public $email; public $password; public $phone; public $gender; public $specialist; public $created; // constructor with $db as database connection public function __construct($db){ $this->conn = $db; } // read all doctors function read(){ // select all query $query = "SELECT `id`, `name`, `email`, `password`, `phone`, `gender`, `specialist`, `created` FROM " . $this->table_name . " ORDER BY id DESC"; // prepare query statement $stmt = $this->conn->prepare($query); // execute query $stmt->execute(); return $stmt; } // get single doctor data function read_single(){ // select all query $query = "SELECT `id`, `name`, `email`, `password`, `phone`, `gender`, `specialist`, `created` FROM " . $this->table_name . " WHERE id= '".$this->id."'"; // prepare query statement $stmt = $this->conn->prepare($query); // execute query $stmt->execute(); return $stmt; } // create doctor function create(){ //if($this->isAlreadyExist()){ // return false; //} // query to insert record $query = "INSERT INTO ". $this->table_name ." (`id`, `username`) VALUES ('".$this->id."', '".$this->username."')"; // prepare query $stmt = $this->conn->prepare($query); // execute query $stmt->execute(); //if($stmt->execute()){ //$this->id = $this->conn->lastInsertId(); //return true; //} return false; } // update doctor function update(){ // query to insert record $query = "UPDATE " . $this->table_name . " SET name='".$this->name."', email='".$this->email."', password='".$this->password."', phone='".$this->phone."', gender='".$this->gender."', specialist='".$this->specialist."' WHERE id='".$this->id."'"; // prepare query $stmt = $this->conn->prepare($query); // execute query if($stmt->execute()){ return true; } return false; } // delete doctor function delete(){ // query to insert record $query = "DELETE FROM " . $this->table_name . " WHERE id= '".$this->id."'"; // prepare query $stmt = $this->conn->prepare($query); // execute query if($stmt->execute()){ return true; } return false; } function isAlreadyExist(){ $query = "SELECT * FROM " . $this->table_name . " WHERE email='".$this->email."'"; // prepare query statement $stmt = $this->conn->prepare($query); // execute query $stmt->execute(); if($stmt->rowCount() > 0){ return true; } else{ return false; } } }