PHP code example of onesimus-systems / seed-catalog

1. Go to this page and download the library: Download onesimus-systems/seed-catalog 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/ */

    

onesimus-systems / seed-catalog example snippets


# initialize the connection
# connect() will return false if connecting to the database fails.
# connect($dbtype, $host, $database, $username, $password)

$SC = new SC\SC();
$SC->connect('mysql', 'localhost', 'example', 'username', 'password');

# you can also give it a PDO object to use directly

$SC = new SC\SC($pdo);

# read user 1
$SC->readItem('user', 1);
# update the username of user 1
$SC->updateItem('user', 1, ['username' => 'john.doe']);
# create a user
$SC->createItem('user', ['username' => 'jane.doe', 'email' => '[email protected]']);
# delete user 1
$SC->deleteItem('user', 1);

# read all users
$SC->find('user')->read();
# read the users that are marked as verified in a desc order
$SC->find('user')->whereEqual('is_verified', 1)->orderDesc('id')->read();
# read the user with the most reputation
$SC->find('user')->limit(1)->orderDesc('reputation')->readRecord();
# mark users 1 and 3 as verified
$SC->find('user')->whereIn('id', [1, 3])->update(['is_verified' => 1]);
# count the users that don't have a location
$SC->find('user')->whereNull('location')->count();
# plain sql conditions are also supported
$SC->find('user')->where('is_verified = ?', [1])->read();

# read the users that have a featured post
$SC->find('user')->has('post')->whereEqual('post.is_featured', 1)->read();
# read the posts of user 1
$SC->find('post')->belongsTo('user')->whereEqual('user.id', 1)->read();
# read the posts that are tagged "php"
$SC->find('post')->hasAndBelongsTo('tag')->whereEqual('tag.name', 'php')->read();
# unconventional FK names are also supported
$SC->find('user')->has('post', 'author_id')->whereEqual('user.id', 1)->read();

# read all users
$SC->read('SELECT * FROM user');
# read user 1
$SC->readRecord('SELECT * FROM user WHERE id = ?', [1]);
# read the username of user 1
$SC->readField('SELECT username FROM user WHERE id = ?', [1]);
# read all usernames
$SC->readFields('SELECT username FROM user');
# update all users
$SC->update('UPDATE INTO user SET is_verified = ?', [1]);