PHPackages                             erwang/dataobject - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. erwang/dataobject

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

erwang/dataobject
=================

PHP ORM in one single file

v1.0.8(7y ago)2791[2 issues](https://github.com/erwang/DataObject/issues)PHP

Since Sep 30Pushed 7y ago2 watchersCompare

[ Source](https://github.com/erwang/DataObject)[ Packagist](https://packagist.org/packages/erwang/dataobject)[ RSS](/packages/erwang-dataobject/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (8)Used By (0)

ErwanG\\DataObject
==================

[](#erwangdataobject)

Class DataObject

```
@package ErwanG

```

Database structure :

- each table must have a primary key named "id" with type varchar(20)
- foreign key must be tableName\_id
- associative tables must be TableName1\_TableName2 (where TableName1&lt;TableName2 in alphabetic order)

Example:

```

Book : id, title, editor_id

Author : id, firstName, lastName, birthDate

Author_Book : id, author_id, book_id

Editor : id, name

```

More examples in examples.php;

\_\_construct
-------------

[](#__construct)

DataObject constructor.

get
---

[](#get)

return object with id

```
$book = Book::get('ABC');
```

```
@param $id

@return mixed|null

```

setPDO
------

[](#setpdo)

must be call to set PDO connection

```

DataObject::setPDO(['dbname'=>'database','host'=>'127.0.0.1','username'=>'root','password'=>'123456']);

```

```
@param $params must contain keys dbname, hostn username, password

@return PDO

```

\_prepare
---------

[](#_prepare)

```
@param $query

@return \PDOStatement

```

query
-----

[](#query)

execute query and return result as DataObject

must be use for SELECT queries only

```
@param $query

@param array $params

@return array

```

exec
----

[](#exec)

execute query and return result

```
@param $query

@param array $params

@return \PDOStatement

```

getTable
--------

[](#gettable)

return name table

default value is class name

```
@return string

```

getColumns
----------

[](#getcolumns)

return table columns

```
@return mixed

```

where
-----

[](#where)

return DataObject from where query

```
@param $where

@param array $params

@param null $order

@param null $limit

@return DataObject[]

```

whereFirst
----------

[](#wherefirst)

return first DataObject from where query

```
@param $where

@param array $params

@param null $order

@return DataObject|null

```

whereLast
---------

[](#wherelast)

return last DataObject from where query

```
@param $where

@param array $params

@param null $order

@return DataObject|null

```

find
----

[](#find)

return DataObject from associative array

```

Book:find(['type'=>'thriller");

```

```
@param $params

@param null $order

@param null $limit

@return array

```

findFirst
---------

[](#findfirst)

return first DataObject from associative array

```
@param $params

@param $order

@param bool $create if true, create object if not find

@return DataObject|null

```

findLast
--------

[](#findlast)

return last DataObject from associative array

```
@param $params

@param $order

@return DataObject|null

```

findAll
-------

[](#findall)

return all object

```
@param null $order

@param null $limit

@return array

```

\_\_get
-------

[](#__get)

```
@param $name

@return array

@throws \Exception

```

create
------

[](#create)

create a DataObject from associative array

```

$author = Author::create(['firstname'=>'Victor','lastname'=>'HUGO']);

```

```
@param $params

@return DataObject

```

order
-----

[](#order)

Set string ORDER BY...

```
@param $order

@return string

```

limit
-----

[](#limit)

Set string LIMIT...

```
@param $limit

@return string

```

count
-----

[](#count)

return count from where query

```
@param null $where

@param $params

@return int

```

isInDatabase
------------

[](#isindatabase)

return true if object is in database

```
@return bool

```

defineId
--------

[](#defineid)

return an uniq id

```
@return bool|string

```

hasMany
-------

[](#hasmany)

return object with relation

```

$books = $victorHugo->hasMany(Book::class);

```

```
@param string $class

@return array

@throws \Exception

```

\_getNamespace
--------------

[](#_getnamespace)

```
@return string

```

\_getClass
----------

[](#_getclass)

```
@return string

```

getModel
--------

[](#getmodel)

```
@param null $separator

@return mixed|string

```

\_getClassBetween
-----------------

[](#_getclassbetween)

```
@param $class

@param bool $namespace

@return string

```

store
-----

[](#store)

Store object in database

```
@return $this

@throws \Exception

```

delete
------

[](#delete)

delete object in database

```
@return bool

```

tableExists
-----------

[](#tableexists)

return true if table exists

```
@return boolean

```

hasColumn
---------

[](#hascolumn)

test column existence

```
@param string $column column name

@return boolean

```

drop
----

[](#drop)

drop table

```
@param bool $foreignKeyCheck

@return bool

```

truncate
--------

[](#truncate)

truncate table

```
@example CLASS::truncate(false);

@param bool $foreignKeyCheck

@return bool

```

populate
--------

[](#populate)

populate object with associative array

```
@param $params

@return $this

```

isEqualTo
---------

[](#isequalto)

```
@param Object $object

@return bool

```

copy
----

[](#copy)

copy object without id param

```
@return DataObject

```

beginTransaction
----------------

[](#begintransaction)

begin transaction if none has been started

commit
------

[](#commit)

commit transaction

rollback
--------

[](#rollback)

roll back

###  Health Score

25

↓

LowBetter than 40% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~31 days

Total

7

Last Release

2598d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/74616f9326f0a3c576e8a02321fd46372dd549e7efbee6ebb417b2d45d8f418c?d=identicon)[erwang](/maintainers/erwang)

---

Top Contributors

[![erwang](https://avatars.githubusercontent.com/u/425167?v=4)](https://github.com/erwang "erwang (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/erwang-dataobject/health.svg)

```
[![Health](https://phpackages.com/badges/erwang-dataobject/health.svg)](https://phpackages.com/packages/erwang-dataobject)
```

###  Alternatives

[api-platform/schema-generator

Various tools to generate a data model based on Schema.org vocables

4714.2M6](/packages/api-platform-schema-generator)[user11001/eloquent-model-generator

Eloquent Model Generator

9763.6k](/packages/user11001-eloquent-model-generator)[contributte/nextras-orm-generator

Nextras ORM Generator

20707.7k](/packages/contributte-nextras-orm-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
