// ---------- Conversation & Messages ---------- function createConversation($user_id, $title = 'New Chat') { $pdo = getDB(); $stmt = $pdo->prepare("INSERT INTO conversations (user_id, title) VALUES (?, ?)"); $stmt->execute([$user_id, $title]); return $pdo->lastInsertId(); } function saveMessage($conversation_id, $role, $content) { $pdo = getDB(); $stmt = $pdo->prepare("INSERT INTO messages (conversation_id, role, content) VALUES (?, ?, ?)"); $stmt->execute([$conversation_id, $role, $content]); // Update conversation updated_at $stmt2 = $pdo->prepare("UPDATE conversations SET updated_at = NOW() WHERE id = ?"); $stmt2->execute([$conversation_id]); return $pdo->lastInsertId(); } function getConversations($user_id) { $pdo = getDB(); $stmt = $pdo->prepare("SELECT * FROM conversations WHERE user_id = ? ORDER BY updated_at DESC"); $stmt->execute([$user_id]); return $stmt->fetchAll(PDO::FETCH_ASSOC); } function getMessages($conversation_id) { $pdo = getDB(); $stmt = $pdo->prepare("SELECT * FROM messages WHERE conversation_id = ? ORDER BY created_at ASC"); $stmt->execute([$conversation_id]); return $stmt->fetchAll(PDO::FETCH_ASSOC); } function deleteConversation($conversation_id, $user_id) { $pdo = getDB(); // Ensure the conversation belongs to the user $stmt = $pdo->prepare("DELETE FROM conversations WHERE id = ? AND user_id = ?"); return $stmt->execute([$conversation_id, $user_id]); } function updateConversationTitle($conversation_id, $title) { $pdo = getDB(); $stmt = $pdo->prepare("UPDATE conversations SET title = ? WHERE id = ?"); return $stmt->execute([$title, $conversation_id]); } AI CodeGen – Smart Coding Assistant

Supercharge Your Coding with AI

Get instant code suggestions, debug errors, and learn new languages β€” powered by DeepSeek and Gemini.

Start Coding Free
⚑ 100k+ requests served 🌍 Trusted by developers

Why AI CodeGen?

πŸ€– Two AI Models

Choose between DeepSeek and Gemini for different strengths.

πŸ”’ Secure & Private

Your code is yours. We don't store your queries.

πŸ’³ Monthly Subscription

Unlimited access for a low monthly fee via Razorpay.