PHP code example of evensonarisnord / softlands

1. Go to this page and download the library: Download evensonarisnord/softlands library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

evensonarisnord / softlands example snippets


// Fichier de démarrage de l'application (index.php, bootstrap, etc.)

use Evensonarisnord\Softlands\Database;

Database::setConfig([
    'host'      => '127.0.0.1',
    'db_name'   => 'ecommerce_app',
    'user'      => 'api_user',
    'password'  => 'votre_mot_de_passe_securise',
    'charset'   => 'utf8mb4' // Optionnel
]);



// Assurez-vous d'inclure l'autoload de Composer
uration (Doit être appelée au début) ---
Database::setConfig([
    'host' => '127.0.0.1', 
    'db_name' => 'test_db', 
    'user' => 'root', 
    'password' => ''
]);

// --- 2. Récupération et Utilisation ---
try {
    // Récupère l'unique instance PDO. La connexion est établie ici.
    $pdo = Database::getConnection(); 
    
    // Exemple de requête préparée
    $id = 5;
    $stmt = $pdo->prepare("SELECT nom, prix FROM produits WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();
    
    $produit = $stmt->fetch(PDO::FETCH_ASSOC);

    echo "Produit trouvé : " . $produit['nom'];

} catch (\Exception $e) {
    // Gérer les erreurs (connexion, requête, etc.)
    echo "Une erreur critique est survenue: " . $e->getMessage();
}