PHPackages                             entomb/obj\_mysql - 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. entomb/obj\_mysql

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

entomb/obj\_mysql
=================

MySQL abstraction layer

1(11y ago)2921324[4 issues](https://github.com/entomb/OBJ-MySQL/issues)GPL 3.0PHPPHP &gt;=5.2.0

Since Dec 4Pushed 11y ago7 watchersCompare

[ Source](https://github.com/entomb/OBJ-MySQL)[ Packagist](https://packagist.org/packages/entomb/obj_mysql)[ Docs](https://github.com/entomb/OBJ-MySQL)[ RSS](/packages/entomb-obj-mysql/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

OBJ-MySQL
=========

[](#obj-mysql)

[![Latest Stable Version](https://camo.githubusercontent.com/eed0a798d810100f06e4faac20929e68784f4728473a856dfd4b641476fa6354/68747470733a2f2f706f7365722e707567782e6f72672f656e746f6d622f6f626a5f6d7973716c2f762f737461626c652e706e67)](https://packagist.org/packages/entomb/obj_mysql)[![Total Downloads](https://camo.githubusercontent.com/e93ddb7e5209703ffb0c945cff84d0ba1bfdf717f5334e0cc2f6c59ca78ccfc4/68747470733a2f2f706f7365722e707567782e6f72672f656e746f6d622f6f626a5f6d7973716c2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/entomb/obj_mysql)[![Bitdeli Badge](https://camo.githubusercontent.com/174a12384fe83fa7f889d4cc7af7a7830f67c809dcb3f09ddfdbda6b95c380e0/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f656e746f6d622f6f626a2d6d7973716c2f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

OBJ MySQL is a simple MySQL Abstraction Layer for PHP&gt;5.2 that provides a simple and *secure* interaction with your database using mysqli\_\* functions at its core.

OBJ-MySQL is perfect for small scale applications such as cron jobs, facebook canvas campaigns or micro frameworks or sites.

*This project is under construction, any feedback would be appreciated*

Author: [Jonathan Tavares](https://github.com/entomb)

**checkout the [changelog](https://github.com/entomb/OBJ-MySQL/wiki/changelog) for info on the latest changes**

\##Get OBJ\_MySQL You can download it from here, or require it using [composer](https://packagist.org/packages/entomb/obj_mysql).

```
{
    "require": {
		"entomb/obj_mysql": "dev-master"
	}
}
```

Or you can require it by cloning this repo

```
$ git clone https://github.com/entomb/OBJ-MySQL.git
```

If you are already using GIT on you project you can add it as a submodule

```
$ git submodule add https://github.com/entomb/OBJ-MySQL.git libs/db
```

\##Starting the driver To start the db driver you must include the main class file and pass the '$config' array described bellow. you can have multiple instances of the Class each one with its own $config (one for Reads and one for Writes for example).

```
    //include de main OBJ_mysql class file
    include("bin/OBJ_mysql.php");

    //configuration array
    $config = array();
    $config["hostname"]  = "YOUR_HOST";
    $config["database"]  = "YOUR_DATABASE_NAME";
    $config["username"]  = "USER_NAME";
    $config["password"]  = "PASSWORD";

    //other configurations
    $config["port"]      = "PORT"; //defaults to 3306
    $config["charset"]    = "CHARSET"; //defaults to UTF-8
    $config["exit_on_error"] = "TRUE|FALSE"; //defaults to true
    $config["allow_logging"] = "TRUE|FALSE"; //defaults to true

    //class instantiation
    $db = new OBJ_mysql($config);
```

\##Using OBJ\_MySQL

there are numerous ways of using this library, here are some examples of the most common methods

\###Selecting and retrieving data from a table

```
  $Result = $db->query("SELECT * FROM users");
  $Users  = $Result->fetchALL();
```

\###Inserting data on a table

To manipulate tables you have the most important methods wrapped, they all work the same way: parsing arrays of key/value pairs and forming a safe query

the methods are:

```
  $db->insert( String $Table, Array $Data); //generates an INSERT query
  $db->replace(String $Table, Array $Data); //generates an INSERT OR UPDATE query
  $db->update( String $Table, Array $Data, Array $Where); //generates an UPDATE query
  $db->delete( String $Table, Array $Where); //generates a DELETE query
```

All methods will return the resulting `mysqli_insert_id()` or true/false depending on context. The correct approach if to always check if they executed as success is always returned

```
  $ok = $db->delete('users', array( 'user_id' => 9 ) );
  if($ok){
    echo "user deleted!";
  }else{
    echo "can't delete user!";
  }
```

**note**: All parameter values are sanitized before execution, you don't have to escape values beforehand.

```
  $new_user_id = $db->insert('users', array(
                                'name'  => "jothn",
                                'email' => "johnsmith@email.com",
                                'group' => 1,
                                'active' => true,
                              )
                          );
  if($new_user_id){
    echo "new user inserted with the id $new_user_id";
  }
```

\###binding parameters on queries

Binding parameters is a good way of preventing mysql injections as the parameters are sanitized before execution.

```
  $Result = $db->query("SELECT * FROM users WHERE id_user = ? AND active = ? LIMIT 1",array(11,1));
  if($Result){
    $User = $Result->fetchArray();
    print_r($User);
  }else{
    echo "user not found";
  }
```

\###Using the OBJ\_mysql\_result Class

After executing a `SELECT` query you receive a `OBJ_mysql_result` object that will help you manipulate the resultant data. There are different ways of accessing this data, check the examples bellow:

\####Fetching all data

```
  $Result = $db->query("SELECT * FROM users");
  $AllUsers = $Result->fetchAll();
```

Fetching all data works as `Object` or `Array` the `fetchAll()` method will return the default based on the `$_default_result_type` config. Other methods are:

```
$Row = $Result->fetch();        // Fetch a single result row as defined by the config (Array or Object)
$Row = $Result->fetchArray();   // Fetch a single result row as Array
$Row = $Result->fetchObject();  // Fetch a single result row as Object

$Data = $Result->fetchAll();        // Fetch all result data as defined by the config (Array or Object)
$Data = $Result->fetchAllArray();   // Fetch all result data as Array
$Data = $Result->fetchAllObject();  // Fetch all result data as Object

$Data = $Result->fetchColumn(String $Column);           // Fetch a single column in a 1 dimension Array
$Data = $Result->fetchArrayPair(String $key, String $Value);  // Fetch data as a key/value pair Array.
```

\####Aliases

```
  $db->get()                  // Alias for $db->fetch();
  $db->getAll()               // Alias for $db->fetchAll();
  $db->getObject()            // Alias for $db->fetchAllObject();
  $db->getArray()             // Alias for $db->fetchAllArray();
  $db->getColumn($key)        // Alias for $db->fetchColumn($key);
```

\####Iterations To iterate a resultset, you can use any fetch() method listed above

```
  $Result = $db->query("SELECT * FROM users");

  //using while
  while( $row = $Result->fetch() ){
    echo $row->name;
    echo $row->email;
  }

  //using foreach
  foreach( $Result->fetchAll() as $row ){
    echo $row->name;
    echo $row->email;
  }
```

\####Logging and Errors

Showing the query log. the log comes with the SQL executed, the execution time and the result row count (if any)

```
  print_r($db->log());
```

To debug mysql errors:

Use `$db->errors()` to fetch all errors (returns false if no errors) or `$db->lastError()` for information on the last error.

```
  if( $db->errors() ){
      echo $db->lastError();
  }
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.8% 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 ~547 days

Total

2

Last Release

4365d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e5df6a9383a7cefc454295eb6015927e9ee6e46bf44ef6e79e000f72167cca69?d=identicon)[entomb](/maintainers/entomb)

---

Top Contributors

[![entomb](https://avatars.githubusercontent.com/u/57768?v=4)](https://github.com/entomb "entomb (23 commits)")[![seanhussey](https://avatars.githubusercontent.com/u/10438?v=4)](https://github.com/seanhussey "seanhussey (1 commits)")

---

Tags

mysqldbamysql abstraction layermsqli

### Embed Badge

![Health badge](/badges/entomb-obj-mysql/health.svg)

```
[![Health](https://phpackages.com/badges/entomb-obj-mysql/health.svg)](https://phpackages.com/packages/entomb-obj-mysql)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M36](/packages/scienta-doctrine-json-functions)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)[jv2222/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

87311.3k2](/packages/jv2222-ezsql)[cytopia/mysqldump-secure

Secure mysqldump script with encryption, compression, logging, blacklisting and Nagios monitoring integration

1474.7k1](/packages/cytopia-mysqldump-secure)

PHPackages © 2026

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