PHP code example of retamayo / absl

1. Go to this page and download the library: Download retamayo/absl 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/ */

    

retamayo / absl example snippets




$host = 'localhost';
$dbName = 'your_database_name';
$username = 'your_username';
$password = 'your_password';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbName", $username, $password);
    $absl = new Absl($pdo);
} catch (PDOException $e) {
    echo "Database connection failed: " . $e->getMessage();
    // Handle the connection error gracefully
}

$tableName = 'users';
$primaryKey = 'id';
$columns = ['column1', 'column2', 'column3'];

$absl->defineTable($tableName, $primaryKey, $columns);

$tableName = 'users';

try {
    $absl->useTable($tableName);
} catch (Exception $e) {
    echo "Table selection failed: " . $e->getMessage();
    // Handle the error gracefully
}

$records = $absl->list();

$records = $absl->list(['column1', 'column2']);

$record = $absl->fetch(['column1', 'column2'], 'unique_column_name', 'unique_column_value');

$jsonData = $absl->listJSON();

$record = $absl->fetchJSON(['column1', 'column2'], 'unique_column_name', 'unique_column_value');

$data = [
    'name' => 'John Doe',
    'email' => '[email protected]',
    // Set other column values as needed
];

$newRecordId = $absl->create($data);

$where = 'id';
$whereValue = '1';
$data = [
    'name' => 'Jane Doe',
    'email' => '[email protected]',
    // Update other column values as needed
];

$updatedRows = $absl->update($data, $where, $whereValue);

$where = 'id';
$whereValue = '1';
$deletedRows = $absl->delete($where, $whereValue);

$username = '[email protected]';
$password = 'password123';

if ($absl->authenticate(['column_name_of_username_or_email' => $username, 'column_name_of_password' => $password])) {
    // Authentication successful
} else {
    // Authentication failed
}

$columnName = 'email';
$columnValue = '[email protected]';

if ($absl->checkDuplicate($columnName, $columnValue)) {
    // Value is already present in the column
} else {
    // Value is unique
}