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() { } }