diff options
| author | Syndamia <kamen@syndamia.com> | 2025-01-19 07:58:29 +0200 |
|---|---|---|
| committer | Syndamia <kamen@syndamia.com> | 2025-01-19 07:58:29 +0200 |
| commit | 5c0dad31512870257178e9950ae688e57206dd22 (patch) | |
| tree | 422b1ae3d9f0d50a1efe939a1b08df6474f9d602 | |
| parent | c36724bb6cb37e03d72b0d6f0995e0a91b871edf (diff) | |
| download | nowayforward_human-5c0dad31512870257178e9950ae688e57206dd22.tar nowayforward_human-5c0dad31512870257178e9950ae688e57206dd22.tar.gz nowayforward_human-5c0dad31512870257178e9950ae688e57206dd22.zip | |
feat(database): Return user id upon creation
| -rw-r--r-- | controllers/test.php | 2 | ||||
| -rw-r--r-- | models/database.php | 6 |
2 files changed, 6 insertions, 2 deletions
diff --git a/controllers/test.php b/controllers/test.php index 1b3b2c4..8e79fae 100644 --- a/controllers/test.php +++ b/controllers/test.php @@ -1,5 +1,5 @@ <?php function on_post() { - Database\User::create($_POST["Username"], "", "User"); + echo "Id: " . Database\User::create($_POST["Username"], "", "User"); } diff --git a/models/database.php b/models/database.php index ad0c574..c8123ad 100644 --- a/models/database.php +++ b/models/database.php @@ -23,10 +23,14 @@ class User { return $query->fetch(); } - static function create(string $Username, string $Password, string $Role) { + static function create(string $Username, string $Password, string $Role) : int { $conn = connect(); $query = $conn->query("INSERT INTO Users (Username, Password, Role) VALUES (\"$Username\", \"$Password\", \"$Role\")"); + + // NOTE: If we ever insert more than one values, lastInsertId will returne the first id + $id = $conn->lastInsertId(); $conn = null; + return $id; } static function get_all() : array { |
