1. Go to this page and download the library: Download wnikk/micro-active-record 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/ */
wnikk / micro-active-record example snippets
use Wnikk\MicroActiveRecord\DbConn;
use Wnikk\MicroActiveRecord\ActiveRecord;
// Example for MySQL/MariaDB
DbConn::setConfig([
'dsn' => 'mysql:host=localhost;dbname=testdb;charset=utf8mb4',
'user' => 'dbuser',
'password' => 'dbpass',
'options' => [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
]);
// Or second example for MySQL/MariaDB
// $pdo = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8mb4', 'user', 'pass');
// DbConn::setPdo($pdo);
// Example for MSSQL
//$pdo = new PDO('sqlsrv:Server=localhost;Database=testdb', 'user', 'pass');
//DbConn::setPdo($pdo);
// Example for Oracle
//$pdo = new PDO('oci:dbname=//localhost:1521/XE;charset=UTF8', 'user', 'pass');
//DbConn::setPdo($pdo);
// Now you can use ActiveRecord directly:
$users = ActiveRecord::table('users')
->where('status', 'active')
->get();
ActiveRecord::query('CREATE INDEX idx_pname ON Users (LastName, FirstName);')->execute();
# For get SQL query and bindings add toSql() before any execution method
[$sql, $bindings] = ActiveRecord::table('users')
->where('status', 'active')
->toSql()
->get();
$ar = new ActiveRecord('users');
$ar->returnException = false;
$result = $ar->insert(['login' => null]); // login is NOT NULL
if ($result === null) {
print_r($ar->lastErrors); // See error details
print_r($ar->lastQuery); // See the last attempted SQL
}
use Wnikk\MicroActiveRecord\ActiveRecord;
class User extends ActiveRecord {
// Add custom methods or override behaviors
}
class User extends ActiveRecord {
protected string $table = 'global_users';
protected array $columns = [
'id' => 'int primary key auto_increment',
'login' => 'varchar(255) not null',
'status' => "enum('active','inactive') not null default 'active'",
'created_at' => 'datetime not null',
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.