1. Go to this page and download the library: Download jacked-php/lite-connect 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/ */
jacked-php / lite-connect example snippets
use JackedPhp\LiteConnect\Connection\Connection;
use JackedPhp\LiteConnect\SQLiteFactory;
/** @var Connection $connection */
$connection = SQLiteFactory::make([
'database' => 'path/to/your/database.db',
]);
// When you're done with the connection:
$connection->close();
use JackedPhp\LiteConnect\Migration\MigrationManager;
class CreateUsersTable implements Migration
{
public function up(PDO $pdo): void
{
$pdo->exec('CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NULL,
email TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)');
}
public function down(PDO $pdo): void
{
$pdo->exec('DROP TABLE users');
}
}
$migrationManager = new MigrationManager($connection);
$migrationManager->runMigrations([
new CreateUsersTable(),
]);
use JackedPhp\LiteConnect\Model\BaseModel;
class User extends BaseModel
{
protected string $table = 'users';
protected ?string $primaryKey = 'id';
/**
* @var string[] $fillable
*/
protected array $fillable = [
'name',
'email',
];
}
// Creating a new user
/** @var User $newUser */
$newUser = (new User($connection))->create([
'name' => 'John Doe',
'email' => '[email protected]',
]);
// Finding a user by ID
/** @var User $foundUser */
$foundUser = (new User($connection))->find($newUser->id);
// Updating a user
$foundUser->update([
'email' => '[email protected]',
]);
// Deleting a user
$foundUser->delete();
// or
(new User($connection))->where('name', '=', 'John Doe')->delete();
$users = new User($connection);
$filteredUsers = $users->where('name', '=', 'John Doe')->get();
// or
$orderedUsers = $users->orderBy('id', 'desc')->get();
use OpenSwoole\Core\Coroutine\Pool\ClientPool;
$connectionPool = new ClientPool(
factory: SQLiteFactory::class,
config: [
'database' => 'path/to/your/database.db',
],
size: 1,
);
// here you get the connection:
$connection = $connectionPool->get();
// here you put back the connection:
$connectionPool->put($connection);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.