PHP code example of bazarin / bazarin-php-library

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

    

bazarin / bazarin-php-library example snippets




use Bazarin\Database\Connection;
use Bazarin\Database\QueryBuilder;

// Database Configuration
$db = new Connection([
    'host' => 'localhost',
    'user' => 'bazarin',
    'password' => 'bazarin',
    'database' => 'xgramm'
]);

// Initialize Query Builder
$query = new QueryBuilder($db->getConnection());

$users = $query->select("users", '*', ['username' => 'xgramm']);
print_r($users);

$data = [
    'username' => 'john_doe',
    'email' => '[email protected]',
    'password' => password_hash('securepass', PASSWORD_BCRYPT)
];

$userId = $query->insert('users', $data);
if ($userId) {
    echo "User added successfully with ID: $userId";
}

$updateData = ['email' => '[email protected]'];
$updated = $query->update('users', $updateData, ['username' => 'john_doe']);

if ($updated) {
    echo "User email updated successfully";
}

$deleted = $query->delete('users', ['username' => 'john_doe']);
if ($deleted) {
    echo "User deleted successfully";
}

$authResult = $query->auth('users', 'john_doe', 'securepass');
print_r($authResult);

use Bazarin\Helpers\FileHelper;

$fileHelper = new FileHelper();
$filePath = "uploads/sample.txt";

// Check if a file exists
if ($fileHelper->exists($filePath)) {
    echo "File exists!";
}

use Bazarin\Helpers\DateHelper;

$dateHelper = new DateHelper();

// Get current date
echo $dateHelper->now();

use Bazarin\APIS\Curl;

$curl = new Curl();
$response = $curl->request('https://jsonplaceholder.typicode.com/todos/1', 'GET');
var_dump($response);

use Bazarin\APIS\FileGetContent;

$fileGetContent = new FileGetContent('*');
$content = $fileGetContent->fetch("https://example.com/sample.txt");

echo $content;

use Bazarin\Security\Cryptions;

$cryptions = new Cryptions('my-secret-key');
$encrypted = $cryptions->encrypt("Hello, World!");
$decrypted = $cryptions->decrypt($encrypted);

echo "Encrypted: $encrypted\n";
echo "Decrypted: $decrypted\n";