1. Go to this page and download the library: Download wlib/db 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/ */
wlib / db example snippets
// Connexion SQLite
$db = new Db(Db::DRV_SQLTE, '/chemin/vers/base.sqlite');
// Connexion MySQL
$db = new Db(Db::DRV_MYSQL, 'nom_base', 'utilisateur', 'motdepasse', 'localhost', 3306);
// Connexion PostgreSQL
$db = new Db(Db::DRV_PGSQL, 'nom_base', 'utilisateur', 'motdepasse', 'localhost', 5432);
$db->connect();
// Sélection simple
$result = $db->query()
->select('id, title, views')
->from('post')
->where('id = :id')
->setParameter('id', 1, PDO::PARAM_INT)
->run();
// Récupération des résultats
$row = $result->fetch(); // Un seul résultat
$rows = $result->fetchAll(); // Tous les résultats
$count = $result->fetchColumn(); // Première colonne
$db->execute("
CREATE TABLE post (
id INTEGER PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
views INTEGER NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
)
");
// Requête avec jointure, regroupement et tri
$result = $db->query()
->select('u.name, COUNT(p.id) as post_count')
->from('users AS u')
->leftJoin('post AS p', 'p.user_id = u.id')
->groupBy('u.id')
->orderBy('post_count DESC')
->limit(10)
->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.