31 lines
787 B
PHP
31 lines
787 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
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 user_write(object $pdo, string $username, string $pwd) {
|
|
$query = "INSERT INTO users (username, pwd) VALUES (:username, :pwd)";
|
|
|
|
$stmt = $pdo->prepare($query);
|
|
$stmt->bindParam(":username",$username);
|
|
$stmt->bindParam(":pwd",$pwd);
|
|
$stmt->execute();
|
|
|
|
$stmt = null;
|
|
$query = null;
|
|
} |