Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit 33815e2

Browse files
committed
Library modified to be compatible with PHP 5.6 or higher
1 parent e565e53 commit 33815e2

17 files changed

+104
-109
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 1.1.0 - 2017-01-30
4+
* Compatible with PHP 5.6 or higher.
5+
6+
## 1.0.0 - 2017-01-30
7+
* Compatible only with PHP 7.0 or higher. In the next versions, the library will be modified to make it compatible with PHP 5.6 or higher.
8+
39
## 1.0.0 - 2017-01-09
410
* Added `Josantonius\Database\Database` class.
511
* Added `Josantonius\Database\Database->__connstruct()` method.

README-ES.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ Para instalar PHP Database library, simplemente escribe:
4040

4141
### Requisitos
4242

43-
Esta ĺibrería es soportada por versiones de PHP 7.0 o superiores y es compatible con versiones de HHVM 3.0 o superiores.
44-
45-
Para utilizar esta librería en HHVM (HipHop Virtual Machine) tendrás que activar los tipos escalares. Añade la siguiente ĺínea "hhvm.php7.scalar_types = true" en tu "/etc/hhvm/php.ini".
43+
Esta ĺibrería es soportada por versiones de PHP 5.6 o superiores y es compatible con versiones de HHVM 3.0 o superiores.
4644

4745
### Cómo empezar y ejemplos
4846

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ To install PHP Database library, simply:
4040

4141
### Requirements
4242

43-
This library is supported by PHP versions 7.0 or higher and is compatible with HHVM versions 3.0 or higher.
44-
45-
To use this library in HHVM (HipHop Virtual Machine) you will have to activate the scalar types. Add the following line "hhvm.php7.scalar_types = true" in your "/etc/hhvm/php.ini".
43+
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
4644

4745
### Quick Start and Examples
4846

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "josantonius/database",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"type": "library",
55
"description": "Library for SQL database management to be used by several providers at the same time.",
66
"keywords": [
@@ -25,7 +25,7 @@
2525
"minimum-stability": "dev",
2626
"prefer-stable" : true,
2727
"require": {
28-
"php" : ">=7.0"
28+
"php" : ">=5.6"
2929
},
3030
"autoload": {
3131
"psr-4": {

src/Database.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Library for SQL database management to be used by several providers at the same time.
44
*
@@ -8,9 +8,9 @@
88
* @author Josantonius - [email protected]
99
* @copyright Copyright (c) 2017 JST PHP Framework
1010
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
11-
* @version 1.0.0
11+
* @version 1.1.0
1212
* @link https://github.com/Josantonius/PHP-Database
13-
* @since File available since 1.0.0 - Update: 2017-01-09
13+
* @since File available since 1.0.0 - Update: 2017-01-30
1414
*/
1515

1616
namespace Josantonius\Database;
@@ -184,9 +184,7 @@ class Database {
184184
* @throws DBException → if the provider class specified does not exist
185185
* @throws DBException → if there has been no successful connection to the database
186186
*/
187-
private function __construct(string $provider, string $host,
188-
string $dbUser, string $dbName,
189-
string $pass, array $settings) {
187+
private function __construct($provider, $host, $dbUser, $dbName, $pass, $settings) {
190188

191189
$providerClass = 'Josantonius\\Database\\Provider\\' . $provider;
192190

@@ -226,10 +224,8 @@ private function __construct(string $provider, string $host,
226224
*
227225
* @return object → object with the connection
228226
*/
229-
public static function getConnection(string $databaseID,
230-
string $provider, string $host,
231-
string $dbUser, string $dbName,
232-
string $pass, array $settings) {
227+
public static function getConnection($databaseID, $provider, $host, $dbUser,
228+
$dbName, $pass, $settings) {
233229

234230
if (static::$_databaseID !== $databaseID) {
235231

@@ -264,7 +260,7 @@ public static function getConnection(string $databaseID,
264260
* @throws DBException → invalid query type
265261
* @return mixed → result as object, array, int...
266262
*/
267-
public function query(string $query, array $statements = null, string $result = 'obj') {
263+
public function query($query, $statements = null, $result = 'obj') {
268264

269265
$this->_type = explode(" ", $query)[0];
270266

@@ -328,7 +324,7 @@ private function _implementQuery() {
328324
*
329325
* @return object
330326
*/
331-
public function create(array $data) {
327+
public function create($data) {
332328

333329
$this->_type = 'CREATE';
334330

@@ -365,7 +361,7 @@ public function select($columns = '*') {
365361
*
366362
* @return object
367363
*/
368-
public function insert(array $data, array $statements = null) {
364+
public function insert($data, $statements = null) {
369365

370366
$this->_type = 'INSERT';
371367

@@ -386,7 +382,7 @@ public function insert(array $data, array $statements = null) {
386382
*
387383
* @return object
388384
*/
389-
public function update(array $data, array $statements = null) {
385+
public function update($data, $statements = null) {
390386

391387
$this->_type = 'UPDATE';
392388

@@ -407,7 +403,7 @@ public function update(array $data, array $statements = null) {
407403
*
408404
* @return object
409405
*/
410-
public function replace(array $data, array $statements = null) {
406+
public function replace($data, $statements = null) {
411407

412408
$this->_type = 'REPLACE';
413409

@@ -469,7 +465,7 @@ public function drop() {
469465
*
470466
* @return object
471467
*/
472-
public function in(string $table) {
468+
public function in($table) {
473469

474470
$this->_table = $table;
475471

@@ -485,7 +481,7 @@ public function in(string $table) {
485481
*
486482
* @return object
487483
*/
488-
public function table(string $table) {
484+
public function table($table) {
489485

490486
$this->_table = $table;
491487

@@ -501,7 +497,7 @@ public function table(string $table) {
501497
*
502498
* @return object
503499
*/
504-
public function from(string $table) {
500+
public function from($table) {
505501

506502
$this->_table = $table;
507503

@@ -518,7 +514,7 @@ public function from(string $table) {
518514
*
519515
* @return object
520516
*/
521-
public function where($clauses, array $statements = null) {
517+
public function where($clauses, $statements = null) {
522518

523519
$this->_where = $clauses;
524520

@@ -543,7 +539,7 @@ public function where($clauses, array $statements = null) {
543539
*
544540
* @return object
545541
*/
546-
public function order(string $params) {
542+
public function order($params) {
547543

548544
$this->_order = $params;
549545

@@ -559,7 +555,7 @@ public function order(string $params) {
559555
*
560556
* @return object
561557
*/
562-
public function limit(string $params) {
558+
public function limit($params) {
563559

564560
$this->_limit = $params;
565561

@@ -594,7 +590,7 @@ private function _reset() {
594590
*
595591
* @return int → number of lines updated or 0 if not updated
596592
*/
597-
public function execute(string $result = 'obj') {
593+
public function execute($result = 'obj') {
598594

599595
$this->_result = $result;
600596

@@ -711,10 +707,10 @@ private function _fetchResponse() {
711707

712708
if ($this->_result === 'id') { # Display last insert Id
713709

714-
return $this->lastInsertId ?? $this->_provider->lastInsertId() ?? 0;
710+
return $this->lastInsertId;
715711
}
716712

717-
return $this->rowCount ?? $this->_provider->rowCount($this->_response) ?? 0;
713+
return $this->rowCount;
718714

719715
} else if ($this->_type === 'SELECT') {
720716

src/Exception/DBException.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Falta descripción.
44
*
@@ -8,9 +8,9 @@
88
* @author Josantonius - [email protected]
99
* @copyright Copyright (c) 2016 JST PHP Framework
1010
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
11-
* @version 1.0.0
11+
* @version 1.1.0
1212
* @link https://github.com/Josantonius/PHP-Database
13-
* @since File available since 1.0.0 - Update: 2016-12-21
13+
* @since File available since 1.0.0 - Update: 2017-01-30
1414
*/
1515

1616
namespace Josantonius\Database\Exception;
@@ -35,7 +35,7 @@ class DBException extends \Exception {
3535
* @param int $error → error code (Optional)
3636
* @param int $status → HTTP response status code (Optional)
3737
*/
38-
public function __construct(string $msg = '', int $error = 0, int $status = 0) {
38+
public function __construct($msg = '', $error = 0, $status = 0) {
3939

4040
$this->message = $msg;
4141
$this->code = $error;

src/Provider/MSSQLprovider.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php declare(strict_types=1);
1+
<?php
22
/**
33
* Library for SQL database management to be used by several providers at the same time.
44
*
@@ -8,9 +8,9 @@
88
* @author Josantonius - [email protected]
99
* @copyright Copyright (c) 2017 JST PHP Framework
1010
* @license https://opensource.org/licenses/MIT - The MIT License (MIT)
11-
* @version 1.0.0
11+
* @version 1.1.0
1212
* @link https://github.com/Josantonius/PHP-Database
13-
* @since File available since 1.0.0 - Update: 2017-01-09
13+
* @since File available since 1.0.0 - Update: 2017-01-30
1414
*/
1515

1616
namespace Josantonius\Database\Provider;
@@ -39,12 +39,11 @@ class MSSQLprovider extends Provider {
3939
*
4040
* @return object|null → returns the object with the connection or null
4141
*/
42-
public function connect(string $host, string $dbUser,
43-
string $dbName, string $pass, array $settings = []) {
42+
public function connect($host, $dbUser, $dbName, $pass, $settings = []) {
4443

4544
try {
4645

47-
$port = $settings['port'] ?? '1433';
46+
$port = (isset($settings['port']) ? $settings['port'] : '1433';
4847

4948
$this->conn = mssql_connect($host . ':' . $port, $user, $pass);
5049

@@ -70,7 +69,7 @@ public function connect(string $host, string $dbUser,
7069
*
7170
* @return object|null → returns the object with the connection or null
7271
*/
73-
public function query(string $query, string $type = '') {
72+
public function query($query, $type = '') {
7473

7574
try {
7675

@@ -95,7 +94,7 @@ public function query(string $query, string $type = '') {
9594
*
9695
* @return object|null → returns the object with the connection or null
9796
*/
98-
public function statements(string $query, array $statements) { }
97+
public function statements($query, $statements) { }
9998

10099
/**
101100
* Create table statement.
@@ -107,7 +106,7 @@ public function statements(string $query, array $statements) { }
107106
*
108107
* @return int → 0
109108
*/
110-
public function create(string $table, array $data) {
109+
public function create($table, $data) {
111110

112111
$query = 'CREATE TABLE IF NOT EXISTS `' . $table . '` (';
113112

@@ -194,7 +193,7 @@ public function select($columns, $from, $where, $order, $limit, $statements) {
194193
*
195194
* @return object → query response
196195
*/
197-
public function insert(string $table, array $data, $statements) {
196+
public function insert($table, $data, $statements) {
198197

199198
$input = ['columns' => '',
200199
'values' => ''];
@@ -229,7 +228,7 @@ public function insert(string $table, array $data, $statements) {
229228
*
230229
* @return object → query response
231230
*/
232-
public function update(string $table, array $data, $statements, $where) {
231+
public function update($table, $data, $statements, $where) {
233232

234233
$query = 'UPDATE `' . $table . '` SET ';
235234

@@ -270,7 +269,7 @@ public function update(string $table, array $data, $statements, $where) {
270269
*
271270
* @return object → query response
272271
*/
273-
public function replace(string $table, $data, $statements) {
272+
public function replace($table, $data, $statements) {
274273

275274
$columns = array_keys($data);
276275

@@ -301,7 +300,7 @@ public function replace(string $table, $data, $statements) {
301300
*
302301
* @return object → query response
303302
*/
304-
public function delete(string $table, $statements, $where) {
303+
public function delete($table, $statements, $where) {
305304

306305
$query = 'DELETE FROM `' . $table . '` ';
307306

@@ -331,7 +330,7 @@ public function delete(string $table, $statements, $where) {
331330
*
332331
* @return int → 0
333332
*/
334-
public function truncate(string $table) {
333+
public function truncate($table) {
335334

336335
$query = 'TRUNCATE TABLE `' . $table .'`';
337336

@@ -347,7 +346,7 @@ public function truncate(string $table) {
347346
*
348347
* @return int → 0
349348
*/
350-
public function drop(string $table) {
349+
public function drop($table) {
351350

352351
$query = 'DROP TABLE IF EXISTS `' . $table .'`';
353352

@@ -364,7 +363,7 @@ public function drop(string $table) {
364363
*
365364
* @return object|array → object or array with results
366365
*/
367-
public function fetchResponse($response, string $result) {
366+
public function fetchResponse($response, $result) {
368367

369368
if ($response) {
370369

@@ -388,7 +387,7 @@ public function fetchResponse($response, string $result) {
388387
*
389388
* @return int → last row id modified or added
390389
*/
391-
public function lastInsertId(): int { }
390+
public function lastInsertId() { }
392391

393392
/**
394393
* Get rows number.
@@ -399,7 +398,7 @@ public function lastInsertId(): int { }
399398
*
400399
* @return int → rows number in query object
401400
*/
402-
public function rowCount($response): int { }
401+
public function rowCount($response) { }
403402

404403
/**
405404
* Get errors.
@@ -408,7 +407,7 @@ public function rowCount($response): int { }
408407
*
409408
* @return string → get the message if there has been any error
410409
*/
411-
public function getError(): string {
410+
public function getError() {
412411

413412
return $this->error;
414413
}
@@ -420,7 +419,7 @@ public function getError(): string {
420419
*
421420
* @return bool true|false → check the connection and return true or false
422421
*/
423-
public function isConnected(): bool {
422+
public function isConnected() {
424423

425424
return !is_null($this->conn);
426425
}

0 commit comments

Comments
 (0)