Download the PHP package eftec/pdooneorm without Composer

On this page you can find all versions of the php package eftec/pdooneorm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package pdooneorm

Database Access Object wrapper for PHP and PDO in a single class

PdoOneORM. It's a simple ORM wrapper for PHP's PDO library compatible with SQL Server (2008 R2 or higher), MySQL (5.7 or higher) and Oracle (12.1 or higher).

This library tries to work as fast as possible and simply as possible. The complete library, including dependencies is less than 100 files (and less than 30 are code).

This library works differently to Eloquent. While Eloquent is code-first, this library is database first.

PdoOneORM Eloquent and others code-first ORM
Database first. You create the database and it will generate the code Code First. You create the code and it will generate the database
This library is aware of the schema of the database, for example every column of every table. This library is not aware of the schema of the database
Relations are created using foreign keys or manually. Relation could create foreign keys.

Why?

Packagist Total Downloads [Maintenance]() [composer]() [php]() [php]() [CocoaPods]()

Turn this

into this using the ORM.

Table of contents

Examples

There are some examples in the "examples" folder. If you want to run the examples, then you must change the configuration of the database.

Other example here:

Installation

This library requires PHP 7.4 and higher, and it requires the extension PDO and the extension PDO-MYSQL (Mysql), PDO-SQLSRV (sql server) or PDO-OCI (Oracle)

Install (using composer)

Edit composer.json the next requirement, then update composer.

or install it via cli using

composer require eftec/PdoOneORM

Install (manually)

Just download the folder lib from the library and put in your folder project. Then you must include all the files included on it.

How to create a Connection?

Create an instance of the class PdoOne as follows. Then, you can open the connection using the method connect() or open()

where

$dao=new PdoOneORM("mysql","127.0.0.1","root","abc.123","sakila","");

OCI

CLI configuration.

The command line interface is important to generate the code needed. You can also generate code using PHP code but using the CLI is more straightforward. In the command line, runs the next command:

And it will show the next screen

Note: you can use the arrow keys and the TAB key for autocomplete values.

Connect CLI

Selection the option connect, then configure and configure your database. In the next example we will configure a MySql database (schema sakila).

You can't configure a database if your PHP installation is not using the correct drivers (including the PDO Drivers)

If the connect was done successfully (it shows ok), then you can continue.

Save

Once configured, you can save your configuration (save).

Later, if you want to reconfigure, you can load your configuration file using the option load.

The configuration file is stored in a PHP file with extension .config.php

Example:

You can use this file freely in your code, of you could simply copy and paste in your final code.

Create ORM

Once the database is configured, return to the main menu.

In the menu connect, press enter to return to the main menu. then enter repo to go to the repository menu.

It is the ORM menu:

First, we must configure the folder and the namespace where the files will be generated.

The folder and namespace must work with your composer.json configuration (autoload). If you edit your composer.json file, then you must reopen the CLI.

Example of composer.json

Scan

Once the folder is set, you must scan the schema. If you do changes to the schema, then you must re-scan it again.

(optional) detail and type

Optionally you can change the detail of every table, for example how the classes are called, what column are used and to determine the type for every column.

Save

Save the configuration, so you can load it later.

Create

And finally, you can create the PHP files.

It will generate 3 kind of files.

Reload the configuration

You can easily reload the previous configuration by running in the shell

pdooneorm --fileconnect c1 --filerepo p1

where c1 is the first configuration file (without extension), and p1 is the second configuration file.

Using the code generated

Once the code is generated, you could use the repo classes.

1) You must connect to the database once so the repo classes could work correctly. 2) Then you can use the repo classes.

ORM

This library allows creating and use it as an ORM. To use it as an ORM, you must create the classes.

What is an ORM?

An ORM transforms queries to the database in objects serializables.

Let's say the next example

You can also run using the Query Builder

What if you use the same table over and over. You can generate a new class called CustomerRepo and calls the code as

While it is simple, but it also hides part of the implementation. It could hurt the performance a bit, but it adds more simplicity and consistency.

Building and installing the ORM manually

There are several ways to generate a Repository code, it is possible to generate a code using the CLI, the GUI or using the next code:

The code generated looks like this one

Creating the repository class

This method is not recommended. Uses the method to create multiple classes.

There are several ways to create a class, you could use the UI, the CLI or directly via code.

It is an example to create our repository class

It will build our Repository class.

It will generate the next class

Creating multiples repositories classes

In this example, we have two classes, messages and users

It will generate the next classes:

Creating all repositories classes

We could automate even further

Using the Repository class.

For started, the library must know to know where to connect, so you must set an instance of the PdoOne and there are 3 ways to instance it.

The repository class is smart, and it does the next operation:

If the Repository base doesn't have a connection, then it will try to use the latest connection available.

The easiest way is to create an instance of PdoOne();

You could also do it by creating a root function called pdoOneORM()

Or creating a global variable called $pdoOne

Or injecting the instance into the class using the static method Class::setPdoOne()

Using multiples connections

Note: If you are using multiples connections, then you must use the method RepoClass::setPdoOne() and it injects the connection inside the Repository Base.

Every repository base could hold only one connection at the same time

Example:

What if you want to use the same base for different connections? You can't. However, you could copy the files and create two different bases and repositories (or you could generate a code to create a new base and repository classes), then you can use multiples connections.

DDL Database Design Language

The next commands usually are executed alone (not in a chain of methods)

Method Description Example
createTable() Creates the table and indexes using the definition inside the Repo TablaParentRepo::createTable();
createForeignKeys() Create all foreign keys of the table TablaParentRepo::createForeignKeys();
dropTable() Drop the table TablaParentRepo::dropTable();
truncate() Truncate the table TablaParentRepo::truncate();
validTable() Validate if the table hasn't changed $ok=TablaParentRepo::validTable();

Nested Operators

The nested operators are methods that should be in between of our chain of methods.

ClassRepo::op()::where()::finalop() is ✅

ClassRepo::op()::op()::where() will leave the chain open ❌

For example:

Method Description Example
where() It adds a where to the chain TablaParentRepo::where()
order() It adds a order by to the chain TablaParentRepo::order()
group() it adds a group by to the chain TablaParentRepo::group()
limit() It limits the results TablaParentRepo::limit()
page() Its similar to limit but it uses page TablaParentRepo::page()
innerjoin() It adds a inner join to the query TablaParentRepo::innerjoin()
left() It adds a left join to the query TablaParentRepo::left()
right() It adds a right join to the query TablaParentRepo::right()

DQL Database Query Language

We have different methods to generate a DQL (query) command in our database.

If the operation fails, they return a FALSE, and they could trigger an exception.

The next methods should be at the end of the chain. Examples:

ClassRepo::op()::op()::toList() is ✅

ClassRepo::op()::toList()::op() will trigger an exception ❌

Command Description Example
toList() Returns an array of elements $data=TableNameRepo::toList(); // select from tablerepo
$data=TableNameRepo::where('a1=?',[$value])::toList(); // select
from tablerepo where a1=$value
first() Returns a simple row $data=TableNameRepo::first($pk); // select * from tablerepo where pk=$pk (it always returns 1 or zero values)
$data=TableNameRepo::where('a1=?',[$value])::first(); // it returns the first value (or false if not found)
exist() Returns true if a primary key exists $data=TableNameRepo::exist($pk); // returns true if the object exists.
count() Returns the number of rows in a query $data=TableNameRepo::count($conditions);
$data=TableNameRepo::where('a1=?',[$value])::count();

DML Database Model Language

The next methods allow inserting,update or delete values in the database.

Method Description Example
insert It inserts a value into the database. It could return an identity $identity=TablaParentRepo::insert($obj);
update It updates a value into the database. TablaParentRepo::update($obj);
delete It deletes a value from the database. TablaParentRepo::delete($obj);
deletebyId It deletes a value (using the primary key as condition) from the database. TablaParentRepo::deleteById($pk);

Validate the model

It is possible to validate the model. The model is validated using the information of the database, using the type of the column, the length, if the value allows null and if it is identity (auto numeric).

Recursive

A recursive array is an array of strings with values that it could be read or obtained or compared. For example, to join a table conditionally. PdoOne does not use it directly but _BasePdoOneRepo uses it (_BasePdoOneRepo is a class used when we generate a repository service class automatically).

Example

recursive()

It sets a recursive array.

This value is resets each time a chain methods ends.

getRecursive()

It gets the recursive array.

hasRecursive()

It returns true if recursive has some needle.

If $this->recursive is ['*'] then it always returns true.

Benchmark (mysql, estimated)

Library Insert findPk hydrate with time
PDO 671 60 278 887 3,74
PdoOne 774 63 292 903 4,73
LessQL 1413 133 539 825 5,984
YiiM 2260 127 446 1516 8,415
YiiMWithCache 1925 122 421 1547 7,854
Yii2M 4344 208 632 1165 11,968
Yii2MArrayHydrate 4114 213 531 1073 11,22
Yii2MScalarHydrate 4150 198 421 516 9,537
Propel20 2507 123 1373 1960 11,781
Propel20WithCache 1519 68 1045 1454 8,228
Propel20FormatOnDemand 1501 72 994 1423 8,228
DoctrineM 2119 250 1592 1258 18,139
DoctrineMWithCache 2084 243 1634 1155 17,952
DoctrineMArrayHydrate 2137 240 1230 877 16,83
DoctrineMScalarHydrate 2084 392 1542 939 18,887
DoctrineMWithoutProxies 2119 252 1432 1960 19,822
Eloquent 3691 228 708 1413 12,155

PdoOne adds a bit of ovehead over PDO, however it is simple a wrapper to pdo.

Error FAQs

Uncaught Error: Undefined constant eftec_BasePdoOneRepo::COMPILEDVERSION

It means that you are updated PdoOne, and you are using one class generated by the ORM. This class must be re-generated.

Changelist

In a nutshell:

Every major version means that it could break old code. I.e. 1.0 -> 2.0

Every minor version means that it adds a new functionality i.e. 1.5 -> 1.6 (new methods)

Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix)

License

Copyright Jorge Castro Castillo 2023. Dual license, commercial and LGPL-3.0


All versions of pdooneorm with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
eftec/clione Version ^1.35
eftec/pdoone Version ^4.12.1
ext-pdo Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package eftec/pdooneorm contains the following files

Loading the files please wait ....