1. Go to this page and download the library: Download simsoft/adodb-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/ */
simsoft / adodb-orm example snippets
use Simsoft\ADOdb\DB;
use Simsoft\ADOdb\Query;
$config = [
'mysql' => [
'driver' => 'mysqli',
'host' => '127.0.0.1',
'user' => 'username',
'pass' => 'password',
'schema' => 'db_example',
],
/* Sample config
'connection_name' => [
'driver' => 'mysqli',
'host' => '127.0.0.1',
'user' => 'username',
'pass' => 'password',
'schema' => 'database_name',
'debug' => true,
'execute' => [ // run once when the connection is successful.
"SET @@session.time_zone='+00:00'",
],
],*/
];
// Initiate DB config
DB::init($config);
$result = DB::use('mysql')->execute('SELECT * FROM table1 WHERE attr1 = ? AND attr2 = ?', ['value1', 'value2']);
while ($row = $result->fetchRow()) {
print_r($row);
}
// Insert new record
$success = DB::use('mysql')->insert('table', ['attr1' => 'value1', 'attr2' => 'value2']);
// Update an record.
$success = DB::use('mysql')->update('table', ['attr1' => 'value1', 'attr2' => 'value2'], 'id=2');
$success = DB::use('mysql')->update('table', ['attr1' => 'value1', 'attr2' => 'value2'], Query::where('id', 2));
// Return result in array
$result = DB::use('mysql')->getArray('SELECT * FROM user WHERE name LIKE ?', ['%john%']);
// Enable debug mode
$result = DB::use('mysql')->debug()->getArray('SELECT * FROM user WHERE name LIKE ?', ['%john%']);
namespace Model;
use Simsoft\ADOdb\ActiveRecord;
/**
* Class User
*/
class User extends ActiveRecord
{
/** @var string Connection name */
public $_dbat = 'mysql';
/** @var string table name */
public $_table = 'user';
}