PHP code example of iamjohndev / ijd-orm

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

    

iamjohndev / ijd-orm example snippets


use iamjohndev\IJDORM;

// Create a database connection
$connection = new mysqli('localhost', 'username', 'password', 'database');

// Create an instance of IJDORM
$dorm = new IJDORM($connection, 'users');


$user = $dorm->find(1);

$users = $dorm->all();

$query = "SELECT * FROM users WHERE age > ?";
$users = $dorm->get($query, [18]);

$data = [
    'name' => 'John Doe',
    'email' => '[email protected]',
];

$result = $dorm->create($data);

if ($result['success']) {
    echo 'Record created successfully';
} else {
    echo 'Failed to create record: ' . $result['errors'];
}

$rules = [
    'author_name' => '[
    'author_name' => $request->author_name,
], $rules);

if ($createAuthor['success']) {
    echo "Author created successfully";
} else {
    foreach ($createAuthor['errors'] as $field => $errors) {
        foreach ($errors as $error) {
            $_SESSION['errors'][$field][] = $error;
        }
    }
}

$id = 1;
$data = [
    'name' => 'Jane Doe',
    'email' => '[email protected]',
];

<!-- or -->
$id = 1;
$data = array(
    'name' => 'Jane Doe',
    'email' => '[email protected]',
);

$result = $dorm->update($id, $data);

if ($result['success']) {
    echo 'Record updated successfully';
} else {
    echo 'Failed to update record: ' . $result['errors'];
}

$id = 1;

$result = $dorm->delete($id);

if ($result['success']) {
    echo 'Record deleted successfully';
} else {
    echo 'Failed to delete record: ' . $result['errors'];
}


$users = $dorm->where('age', '>', 18)
              ->orderBy('name', 'asc')
              ->limit(10)
              ->get();

foreach ($users as $user) {
    echo $user['name'] . ' - ' . $user['email'] . '<br>';
}