2017 © Pedro Peláez
 

library mysql

MySQLi Wrapper for PHP

image

jrdev/mysql

MySQLi Wrapper for PHP

  • Saturday, July 8, 2017
  • by jrobinsonc
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MySQLi wrapper for PHP.

Build Status Scrutinizer Code Quality Dependency Status, (*1)

Requirements

  1. MySQL 5.5 or newer.
  2. PHP 5.4 or newer.

Installation

Install the latest version with:, (*2)

$ composer require jrdev/mysql

How to use

First, connect to a database:, (*3)

$db = new \jrdev\MySQL('host', 'user', 'pass', 'database');

Next, prepare your data, and call the necessary methods., (*4)

Generic query method

This method accepts only one param, the SQL to execute.
And returns a jrdev\MySQL\Result object., (*5)

$query = $db->query('SELECT ...');

A SELECT statement

This method accepts:, (*6)

  1. tableName: The name of the table.
  2. fields: (Optional) The fields you want to obtain in the result. Accepts array or string
  3. where: (Optional) The where. Accepts array, string or intenger
  4. orderBy (Optional) The order by.
  5. limit (Optional) The limit.

Returns a jrdev\MySQL\Result object., (*7)

$query = $db->select('table_name', 'field1, field2');

if ($query)
{
    echo 'Num Rows: ', $query->num_rows, '<br>';

    foreach ($query as $row) 
    {
        echo $row['first_name'], '<br>';
    }
}
else
{
    echo $db->error();
}

// The $where (third param) accepts array, string or integer:
$query = $db->select('table_name', 'field1', ['name' => 'Pepe']); // With array.
$query = $db->select('table_name', 'field1', 'name = "Pepe"'); // With string.
$query = $db->select('table_name', 'field1', 1); // With integer. In this case, the resulting sql for the "WHERE" is "id = 1".

An INSERT statement

This method accepts:, (*8)

  1. tableName: The name of the table.
  2. fields: The fields you want to insert.

Returns the ID of the inserted row, or FALSE on error., (*9)

$inserted_id = $db->insert('table_name', [
    'field1' => 'Value 1',
    'field2' => 2,
]);

An UPDATE statement

This method accepts:, (*10)

  1. tableName: The name of the table.
  2. fields: The fields to update.
  3. where: The where. Accepts array, string or intenger.
  4. limit (Optional) The limit of rows to update.

Returns the number of affected rows, or FALSE on error., (*11)

// NOTE: The $where (third param) like the select method accepts array, string or integer.

$row = [
    'field1' => 'Value',
];

$updated_rows = $db->update('table_name', $row, ['id' => 58]); // With array.
$updated_rows = $db->update('table_name', $row, 'id=58'); // With string.
$updated_rows = $db->update('table_name', $row, 58); // With integer.

A DELETE statement

This method accepts:, (*12)

  1. tableName: The name of the table.
  2. where: The where. Accepts array, string or intenger.
  3. limit (Optional) The limit of rows to delete.

Returns the number of affected rows, or FALSE on error., (*13)

// NOTE: The $where (second param) like the select method accepts array, string or integer.

$deleted_rows = $db->delete('table_name', ['id' => 58]); // With array.
$deleted_rows = $db->delete('table_name', 'id=58'); // With string.
$deleted_rows = $db->delete('table_name', 58); // With integer.

License

Licensed under the MIT licence., (*14)

The Versions

08/07 2017

dev-master

9999999-dev https://github.com/jrobinsonc/mysql/blob/master/README.md

MySQLi Wrapper for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

database wrapper mysql mysqli

08/07 2017

v1.x-dev

1.9999999.9999999.9999999-dev https://github.com/jrobinsonc/mysql/blob/master/README.md

MySQLi Wrapper for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

database wrapper mysql mysqli

08/07 2017

v1.0.0

1.0.0.0 https://github.com/jrobinsonc/mysql/blob/master/README.md

MySQLi Wrapper for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

database wrapper mysql mysqli

05/06 2017

v1.0.0-rc.1

1.0.0.0-RC1 https://github.com/jrobinsonc/mysql/blob/master/README.md

MySQLi Wrapper for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

database wrapper mysql mysqli