simsoft / adodb-orm
ORM wrapper for ADOdb PHP
1.1.7
2024-11-05 20:04 UTC
Requires
- php: ^8
- adodb/adodb-php: ^5.22
Requires (Dev)
- phpunit/phpunit: ^9.5
- dev-master
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-develop
This package is auto-updated.
Last update: 2024-11-05 20:08:32 UTC
README
This is an ORM wrapper for ADOdb (https://adodb.org/)
Requirements
- PHP >= 8
Installation
- Install package using composer
$ composer require simsoft/adodb-orm
Getting Started
require_once "vendor/autoload.php"; require_once "vendor/adodb/adodb-php/adodb-active-recordx.inc.php"; 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%']);
Basic Usage
Query Builder
require_once "vendor/autoload.php"; require_once "vendor/adodb/adodb-php/adodb-active-recordx.inc.php"; use Simsoft\ADOdb\DB; use Simsoft\ADOdb\Query; $config = [ 'mysql' => [ 'driver' => 'mysqli', 'host' => '127.0.0.1', 'user' => 'username', 'pass' => 'password', 'schema' => 'db_example', ], ]; DB::init($config); $result = Query::db('mysql')->from('table')->where('attr1', 'value1')->where('attr2', 'value2')->execute(); while ($row = $result->fetchRow()) { print_r($row); }
Active Record
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'; }
require_once "vendor/autoload.php"; require_once "vendor/adodb/adodb-php/adodb-active-recordx.inc.php"; use Simsoft\ADOdb\DB; use Model\User; $config = [ 'mysql' => [ 'driver' => 'mysqli', 'host' => '127.0.0.1', 'user' => 'username', 'pass' => 'password', 'schema' => 'db_example', ], ]; DB::init($config); $users = User::query()->where('age', '>', 20)->where('gender', 'male')->findAll(); foreach ($users as $user) { echo $user->first_name; echo $user->last_name; }
Documentations
License
The WeCanTrack PHP API is licensed under the MIT License. See the LICENSE file for details