commit e41402c6002038e598810babefd928a895589431 Author: stepan323446 Date: Wed Dec 24 14:04:28 2025 +0100 init diff --git a/category.php b/category.php new file mode 100644 index 0000000..34cf288 --- /dev/null +++ b/category.php @@ -0,0 +1,17 @@ + 'localhost', + "USER" => 'integ_user', + "PASSWORD" => '323446', + "DB" => 'web_prog_task_15', + "CHARSET" => 'utf8mb4' +]; + +$dsn = "mysql:host=" . PARAMS['HOST'] . ";dbname=" . PARAMS['DB'] . ";charset=" . PARAMS['CHARSET']; + +$pdoOptions = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false +]; \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..6faf6a6 --- /dev/null +++ b/functions.php @@ -0,0 +1,71 @@ +getCode()); + throw new \PDOException($e->getMessage()); + } + + return $pdo; +} + +function parseCategories(string $cat_string) +{ + $cat_string = trim($cat_string); + $cats = explode(" ", $cat_string); + + $filtered_cats = array_filter($cats, function($cat) { + if(mb_strlen($cat) <= 4) + return false; + + return(ctype_alnum($cat)); + }); + + return $filtered_cats; +} + +function insertCategories(array $cats) { + global $pdo; + + try { + $pdo->beginTransaction(); + + $stmt = $pdo->prepare("INSERT INTO categories (name, code) VALUES (:name, :code)"); + foreach ($cats as $cat_code => $cat_name) { + $stmt->execute([ + ':name' => $cat_name, + ':code' => $cat_code + ]); + } + + $pdo->commit(); + } + catch (Exception $e) { + $pdo->rollBack(); + throw $e; + } +} + +class User { + function createUser() { + + } + function createUserStmt() { + + } + function createUsers() { + + } +} \ No newline at end of file diff --git a/insert.php b/insert.php new file mode 100644 index 0000000..c92d095 --- /dev/null +++ b/insert.php @@ -0,0 +1,4 @@ +