Skip to content

Commit 81a00ed

Browse files
committed
Merge branch 'ready' into newmaster
2 parents 62c4313 + 12abbb9 commit 81a00ed

File tree

8 files changed

+135
-63
lines changed

8 files changed

+135
-63
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"VARBIT",
2020
"VARCHAR",
2121
"autoload",
22+
"cacert",
2223
"codecov",
2324
"ezmysqli",
2425
"ezpdo",
@@ -30,7 +31,9 @@
3031
"isfile",
3132
"mysqli",
3233
"pgsql",
34+
"phpunit",
3335
"postgresql",
36+
"privatekey",
3437
"repo",
3538
"sqlserver",
3639
"sqlsrv",

README.md

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
[![codecov](https://codecov.io/gh/ezSQL/ezSQL/branch/v4/graph/badge.svg)](https://codecov.io/gh/ezSQL/ezSQL)
66
[![Maintainability](https://api.codeclimate.com/v1/badges/0071eb99ab4f5ac5b1f2/maintainability)](https://codeclimate.com/github/ezSQL/ezSQL/maintainability)
77

8-
***Class to make it very easy to deal with database connections.***
8+
***A class to make it very easy to deal with database connections.***
99

1010
This is [__version 4__](https://github.com/ezSQL/ezSQL/tree/v4) that has many modern programming practices in which will break users of version 3.
1111

1212
[__Version 3__](https://github.com/ezSQL/ezSQL/tree/v3) broke version 2.1.7 in one major way, it required *PHP 5.6*. Which drop mysql extension support, other than that, nothing as far using the library was changed, only additional features.
1313

14-
This library has an `Database` class, a combination of the [Factory](https://en.wikipedia.org/wiki/Factory_method_pattern) pattern with an [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) container hosting. The library is following many OOP principles, one in which, properties public access has been removed.
14+
This library has an `Database` class, an combination of the [Factory](https://en.wikipedia.org/wiki/Factory_method_pattern) pattern with an [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) container hosting. This library now is following many OOP principles, one in which, the methods properties public access has been removed. This library also following PSR-2, PSR-4, and PSR-11 conventions.
1515

16-
- More Todo...
16+
* More Todo...
1717

1818
For an full overview see [documentation Wiki](https://github.com/ezSQL/ezSQL/WIKI.md), which is not completely finish.
1919

@@ -26,18 +26,84 @@ For an full overview see [documentation Wiki](https://github.com/ezSQL/ezSQL/WIK
2626
```php
2727
require 'vendor/autoload.php';
2828

29-
// '****' is one of **mysqli**, **pgsql**, **sqlsrv**, **sqlite3**, or **Pdo**.
29+
// **** is one of mysqli, pgsql, sqlsrv, sqlite3, or Pdo.
3030
use ezsql\Database;
3131

32-
$db = Database::initialize('****', [$dsn_path_user, $password, $database, $or, $other_settings], $optional_instance_tag);
32+
$db = Database::initialize('****', [$dsn_path_user, $password, $database, $other_settings], $optional_tag);
3333

3434
// Is same as:
3535
use ezsql\Config;
3636
use ezsql\Database\ez_****;
3737

38-
$setting = new Config('****', [$dsn_path_user, $password, $database, $or, $other_settings]);
38+
$setting = new Config('****', [$dsn_path_user, $password, $database, $other_settings]);
3939

4040
$db = new ez_****($settings);
4141
```
4242

43+
This library will assume the developer is using some sort of IDE with intellisense enabled. The comments/doc-block area will hold any missing documentations. For additional examples see __phpunit__ tests, The tests are fully functional integration tests, meaning the are live database tests, no mocks.
44+
45+
##### General Methods
46+
---
47+
to_string($arrays, $separation = ',');
48+
clean($string);
49+
create_cache(string $path = null);
50+
securePDO($vendor = null,
51+
$key = 'certificate.key',
52+
$cert = 'certificate.crt',
53+
$ca = 'cacert.pem',
54+
$path = '.'._DS
55+
);
56+
createCertificate(string $privatekeyFile = certificate.key,
57+
string $certificateFile = certificate.crt,
58+
string $signingFile = certificate.csr,
59+
string $ssl_path = null, array $details = [commonName => localhost]
60+
);
61+
62+
___Shortcut Table Methods___
63+
64+
create(string $table = null, ...$schemas);// $schemas requires... column()
65+
column(string $column = null, string $type = null, ...$args);
66+
drop(string $table);
67+
---
68+
69+
innerJoin(string $leftTable = null, string $rightTable = null,
70+
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
71+
72+
leftJoin(string $leftTable = null, string $rightTable = null,
73+
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
74+
75+
rightJoin(string $leftTable = null, string $rightTable = null,
76+
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
77+
78+
fullJoin(string $leftTable = null, string $rightTable = null,
79+
string $leftColumn = null, string $rightColumn = null, $condition = EQ);
80+
---
81+
82+
```php
83+
prepareOn(); // When activated will use prepare statements for all shortcut SQL Methods calls.
84+
prepareOff(); // When off shortcut SQL Methods calls will use vendors escape routine instead. This is the default behavior.
85+
```
86+
87+
### Shortcut SQL Methods
88+
89+
* `having(...$having);`
90+
* `groupBy($groupBy);`
91+
* `union(string $table = null, $columnFields = '*', ...$conditions);`
92+
* `unionAll(string $table = null, $columnFields = '*', ...$conditions);`
93+
* `orderBy($orderBy, $order);`
94+
* `limit($numberOf, $offset = null)`
95+
* `where( ...$whereKeyArray);`
96+
* `selecting(string $table = null, $columnFields = '*', ...$conditions);`
97+
* `create_select(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere);`
98+
* `select_into(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere);`
99+
* `update(string $table = null, $keyAndValue, ...$whereKeys);`
100+
* `delete(string $table = null, ...$whereKeys);`
101+
* `replace(string $table = null, $keyAndValue);`
102+
* `insert(string $table = null, $keyAndValue);`
103+
* `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$fromWhere);`
104+
105+
---
106+
107+
query_prepared(string $query_string, array $param_array);
108+
43109
**For** **[Authors/Contributors](https://github.com/ezsql/ezsql/CONTRIBUTORS.md)**

WIKI.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,38 @@ This version further break things introduced in version 3 that broke version 2.1
161161
____Installation and Usage____
162162
---
163163

164-
Note: __****__ is one of '**mysqli**, **pgsql**, **sqlsrv**, **sqlite3**, or **Pdo**'.
165164

166165
Either: ***for version 3.x***
167166

168-
composer require ezsql/ezsql=^3.1.0
169-
require 'vendor/autoload.php';
170-
---------
171-
// Manually download https://github.com/ezSQL/ezSQL/archive/v3.zip and extract.
172-
require 'ez_sql_loader.php';
173-
---------
167+
composer require ezsql/ezsql=^3.1.2
174168

175-
$db = new ezSQL_****(user, password, database, or, other settings);
169+
```php
170+
require 'vendor/autoload.php';
171+
```
172+
```php
173+
// Manually download https://github.com/ezSQL/ezSQL/archive/v3.zip and extract.
174+
require 'ez_sql_loader.php';
175+
```
176+
```php
177+
$db = new ezSQL_****(user, password, database, or, other settings);
178+
```
176179

177180
Or: ***for version 4.x***
178181

179182
// composer is required for version 4
180183
composer require ezsql/ezsql
181-
require 'vendor/autoload.php';
182-
---------
183184

184-
$db = Database::initialize('****', [user, password, database, or, other settings], **optional storage tag);
185+
```php
186+
require 'vendor/autoload.php';
187+
188+
$db = Database::initialize('****', [user, password, database, other settings], **optional tag);
185189

186-
Is same as:
190+
// Is same as:
191+
$setting = new Config('****', [user, password, database, other settings]);
192+
$db = new ez_****($settings);
193+
```
187194

188-
$setting = new Config('****', [user, password, database, or, other settings]);
189-
$db = new ez_****($settings);
195+
>Note: __****__ is one of **mysqli**, **pgsql**, **sqlsrv**, **sqlite3**, or **Pdo**.
190196
191197
**ezsql** functions
192198
---

appveyor.yml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ clone_folder: c:\projects\php-project-workspace
77
environment:
88
matrix:
99
- php_ver_target: 7.1
10-
- dependencies: current
11-
php_ver_target: 7.2
1210
MYSQL_DATABASE: ez_test
1311
MYSQL_HOST: localhost
1412
MYSQL_USER: root
@@ -40,40 +38,25 @@ init:
4038
install:
4139
- IF EXIST c:\tools\php (SET PHP=0)
4240
- ps: >-
43-
If ($env:php_ver_target -eq "5.6") {
44-
appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y --forcex86 php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
45-
} Else {
4641
appveyor-retry cinst --params '""/InstallDir:C:\tools\php""' --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $env:php_ver_target | sort { [version]($_ -split '\|' | select -last 1) } -Descending | Select-Object -first 1) -replace '[php|]','')
47-
}
4842
- appveyor-retry cinst -y sqlite
4943
- cd c:\tools\php
5044
# Get the MSSQL DLL's
5145
- ps: >-
5246
If ($env:PHP -eq "1") {
53-
If ($env:php_ver_target -eq "5.6") {
54-
$source = "https://cdn.joomla.org/ci/php-sqlsrv.zip"
55-
$destination = "c:\tools\php\php-sqlsrv.zip"
56-
Invoke-WebRequest $source -OutFile $destination
57-
#appveyor-retry appveyor DownloadFile https://cdn.joomla.org/ci/php-sqlsrv.zip
58-
7z x php-sqlsrv.zip > $null
59-
copy SQLSRV\php_sqlsrv_56_nts.dll ext\php_sqlsrv_nts.dll
60-
copy SQLSRV\php_pdo_sqlsrv_56_nts.dll ext\php_pdo_sqlsrv_nts.dll
61-
Remove-Item c:\tools\php\* -include .zip
62-
} Else {
6347
$DLLVersion = "4.3.0"
6448
cd c:\tools\php\ext
6549
$source = "http://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip"
6650
$destination = "c:\tools\php\ext\php_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip"
6751
Invoke-WebRequest $source -OutFile $destination
68-
#appveyor-retry appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip
6952
7z x -y php_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip > $null
7053
$source = "http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip"
7154
$destination = "c:\tools\php\ext\php_pdo_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip"
7255
Invoke-WebRequest $source -OutFile $destination
73-
#appveyor-retry appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip
7456
7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php_ver_target)-nts-vc14-x64.zip > $null
7557
Remove-Item c:\tools\php\ext* -include .zip
76-
cd c:\tools\php}}
58+
cd c:\tools\php
59+
}
7760
- IF %PHP%==1 copy php.ini-production php.ini /Y
7861
- IF %PHP%==1 echo date.timezone="UTC" >> php.ini
7962
- IF %PHP%==1 echo extension_dir=ext >> php.ini
@@ -96,9 +79,9 @@ install:
9679
- IF %PHP%==1 echo extension=php_pdo_sqlite.dll >> php.ini
9780
- IF %PHP%==1 echo extension=php_mysqli.dll >> php.ini
9881
- IF %PHP%==1 echo extension=php_pdo_mysql.dll >> php.ini
99-
- IF %PHP%==1 appveyor-retry appveyor DownloadFile https://xdebug.org/files/php_xdebug-2.5.5-7.0-vc14-nts-x86_64.dll -FileName c:\tools\php\ext\php_xdebug-2.5.5-7.0-vc14-nts-x86_64.dll
82+
- IF %PHP%==1 appveyor-retry appveyor DownloadFile https://xdebug.org/files/php_xdebug-2.6.0-7.1-vc14-nts-x86_64.dll -FileName c:\tools\php\ext\php_xdebug-2.6.0-7.1-vc14-nts-x86_64.dll
10083
- IF %PHP%==1 echo [xdebug] >> php.ini
101-
- IF %PHP%==1 echo zend_extension=php_xdebug-2.5.5-7.0-vc14-nts-x86_64.dll >> php.ini
84+
- IF %PHP%==1 echo zend_extension=php_xdebug-2.6.0-7.1-vc14-nts-x86_64.dll >> php.ini
10285
- IF %PHP%==1 echo zend.assertions=1 >> php.ini
10386
- IF %PHP%==1 echo assert.exception=On >> php.ini
10487
- IF %PHP%==1 echo xdebug.remote_enable=1 >> php.ini

lib/DatabaseInterface.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ public function escape(string $str);
5454
public function sysDate();
5555

5656
/**
57-
* Creates a prepared query, binds the given parameters and returns the result of the executed
57+
* Creates a prepared query, binds the given parameters and returns the result of the executed.
58+
*
59+
* Supplying the the whole query string, and placing '?' within,
60+
* then the same number of arguments in an array.
61+
*
62+
* Example:
63+
* `query_prepared('INSERT INTO unit_test(id, test_key) VALUES(1, ?)', ['test 1']);`
64+
*
65+
* - It will determine arguments type, execute, and return results.
5866
*
5967
* @param string $query
6068
* @param array $param
@@ -89,4 +97,9 @@ public function disconnect();
8997
* Get connection handle
9098
*/
9199
public function handle();
100+
101+
/**
102+
* Reset connection handle
103+
*/
104+
public function reset();
92105
}

lib/ezFunctions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ function setInstance($ezSQL = '') {
313313
function getInstance() {
314314
global $ezInstance;
315315

316-
return $ezInstance;
316+
return ($ezInstance instanceOf DatabaseInterface) ? $ezInstance : null;
317317
}
318318

319319
function clearInstance() {

lib/ezQuery.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function where( ...$whereKeyArray)
391391
return ($where != '1') ? " $whereOrHaving ".$where.' ' : ' ' ;
392392
}
393393

394-
public function selecting($table ='', $columnFields = '*', ...$conditions)
394+
public function selecting(string $table = null, $columnFields = '*', ...$conditions)
395395
{
396396
$getFromTable = $this->fromTable;
397397
$getSelect_result = $this->select_result;
@@ -490,17 +490,17 @@ private function select_sql($table = '', $columnFields = '*', ...$conditions)
490490
return $this->selecting($table, $columnFields, ...$conditions);
491491
}
492492

493-
public function union($table = '', $columnFields = '*', ...$conditions)
493+
public function union(string $table = null, $columnFields = '*', ...$conditions)
494494
{
495495
return 'UNION '.$this->select_sql($table, $columnFields, ...$conditions);
496496
}
497497

498-
public function unionAll($table = '', $columnFields = '*', ...$conditions)
498+
public function unionAll(string $table = null, $columnFields = '*', ...$conditions)
499499
{
500500
return 'UNION ALL '.$this->select_sql($table, $columnFields, ...$conditions);
501501
}
502502

503-
public function create_select($newTable, $fromColumns, $oldTable = null, ...$fromWhere)
503+
public function create_select(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere)
504504
{
505505
if (isset($oldTable))
506506
$this->fromTable = $oldTable;
@@ -517,7 +517,7 @@ public function create_select($newTable, $fromColumns, $oldTable = null, ...$fro
517517
return $this->clearPrepare();
518518
}
519519

520-
public function select_into($newTable, $fromColumns, $oldTable = null, ...$fromWhere)
520+
public function select_into(string $newTable, $fromColumns, $oldTable = null, ...$fromWhere)
521521
{
522522
$this->isInto = true;
523523
if (isset($oldTable))
@@ -534,7 +534,7 @@ public function select_into($newTable, $fromColumns, $oldTable = null, ...$fromW
534534
return $this->clearPrepare();
535535
}
536536

537-
public function update($table = '', $keyAndValue, ...$whereKeys)
537+
public function update(string $table = null, $keyAndValue, ...$whereKeys)
538538
{
539539
if ( ! is_array( $keyAndValue ) || empty($table) ) {
540540
return $this->clearPrepare();
@@ -567,7 +567,7 @@ public function update($table = '', $keyAndValue, ...$whereKeys)
567567
return $this->clearPrepare();
568568
}
569569

570-
public function delete($table = '', ...$whereKeys)
570+
public function delete(string $table = null, ...$whereKeys)
571571
{
572572
if ( empty($table) ) {
573573
return $this->clearPrepare();
@@ -647,17 +647,17 @@ private function _query_insert_replace($table = '', $keyAndValue, $type = '', $e
647647
}
648648
}
649649

650-
public function replace($table = '', $keyAndValue)
650+
public function replace(string $table = null, $keyAndValue)
651651
{
652652
return $this->_query_insert_replace($table, $keyAndValue, 'REPLACE');
653653
}
654654

655-
public function insert($table = '', $keyAndValue)
655+
public function insert(string $table = null, $keyAndValue)
656656
{
657657
return $this->_query_insert_replace($table, $keyAndValue, 'INSERT');
658658
}
659659

660-
public function insert_select($toTable = '', $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$fromWhere)
660+
public function insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$fromWhere)
661661
{
662662
$putToTable = $this->_query_insert_replace($toTable, $toColumns, 'INSERT', false);
663663
$getFromTable = $this->select_sql($fromTable, $fromColumns, ...$fromWhere);

0 commit comments

Comments
 (0)