Transfer to git
This commit is contained in:
49
includes/chat_send_model.inc.php
Normal file
49
includes/chat_send_model.inc.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// Remove after sessions are secured
|
||||
function username_search(object $pdo, string $username) {
|
||||
$query = "SELECT username FROM users WHERE username = :username;";
|
||||
|
||||
// Prepare and check if user already exists
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->bindParam(":username",$username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$stmt = null;
|
||||
$query = null;
|
||||
|
||||
// True if something is found, false if not
|
||||
return $result;
|
||||
}
|
||||
|
||||
function retrieve_user_id(object $pdo, string $username) {
|
||||
$query = "SELECT id FROM users WHERE username = :username;";
|
||||
|
||||
// Prepare and check if user already exists
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->bindParam(":username",$username);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$stmt = null;
|
||||
$query = null;
|
||||
|
||||
// True if something is found, false if not
|
||||
return $result["id"];
|
||||
}
|
||||
|
||||
function write_message(object $pdo, string $username, int $users_id, string $content) {
|
||||
$query = "INSERT INTO comments (username, users_id, content) VALUES (:username, :users_id, :content);";
|
||||
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->bindParam(':username',$username);
|
||||
$stmt->bindParam(':users_id',$users_id);
|
||||
$stmt->bindParam(':content',$content);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = null;
|
||||
$query = null;
|
||||
}
|
||||
Reference in New Issue
Block a user