add challenge 11(portifolio)

This commit is contained in:
vista-man
2025-06-19 01:03:59 +02:00
parent 8faefd26ae
commit 5245c6f9b1
27 changed files with 1937 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?php
// config.php
$host = '100.125.62.25'; // Change if your MySQL server is elsewhere
$db = 'portfolio'; // Change to your database name
$user = 'portifolio'; // Change to your MySQL username
$pass = 'S](L8WpeW_(EGyBP'; // Change to your MySQL password
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
function get_pdo() {
global $dsn, $user, $pass, $options;
return new PDO($dsn, $user, $pass, $options);
}

View File

@@ -0,0 +1,21 @@
<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Add CORS headers
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header('Content-Type: application/json');
require_once 'config.php';
try {
$pdo = get_pdo();
$stmt = $pdo->query('SELECT id, title, description, long_description, image_url, project_url, tags, created_at FROM projects ORDER BY created_at DESC');
$projects = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode($projects);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}

View File

@@ -0,0 +1 @@
<?php phpinfo();

View File

@@ -0,0 +1,17 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'config.php';
try {
$pdo = get_pdo();
echo "Database connection successful!<br>";
// Test query
$stmt = $pdo->query('SELECT COUNT(*) as count FROM projects');
$result = $stmt->fetch();
echo "Number of projects in database: " . $result['count'];
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}