-
Notifications
You must be signed in to change notification settings - Fork 291
/
ezFunctions.php
1422 lines (1333 loc) · 51.3 KB
/
ezFunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
namespace ezsql\functions;
use ezsql\ezQuery;
use ezsql\ezSchema;
use ezsql\Database;
use ezsql\ezQueryInterface;
use ezsql\DatabaseInterface;
use ezsql\ezsqlModelInterface;
if (!\function_exists('ezFunctions')) {
/**
* Initialize and connect a vendor's database.
*
* @param string $sqlDriver - SQL driver
* @param array $connectionSetting SQL connection parameters, in the following:
*```js
* [
* user, // The database user name.
* password, // The database users password.
* database, // The name of the database.
* host, // The host name or IP address of the database server. Default is localhost
* port // The database TCP/IP port. Default is: 5432 - PostgreSQL, 3306 - MySQL
* ]
*```
* for: **mysqli** - (`username`, `password`, `database`, `host`, `port`, `charset`)
* - `charset` // The database charset,
* Default is empty string
*
* for: **postgresql** - (`username`, `password`, `database`, `host`, `port`)
*
* for: **sqlserver** - (`username`, `password`, `database`, `host`, `convertMysqlToMssqlQuery`)
* - `convertMysqlToMssqlQuery` // convert Queries in MySql syntax to MS-SQL syntax
* Default is false
*
* for: **pdo** - (`dsn`, `username`, `password`, `options`, `isFile`?)
* - `dsn` // The PDO DSN connection parameter string
* - `options` // Array for setting connection options as MySQL
* - `isFile` // File based databases like SQLite don't need
* user and password, they work with path in the dsn parameter
* Default is false
*
* for: **sqlite3** - (`filePath`, `database`)
* - `filePath` // The path to open an SQLite database
*
* @param string $instanceTag - Store the instance for later use
* @return \ezsql\Database\ez_pdo|\ezsql\Database\ez_pgsql|\ezsql\Database\ez_sqlsrv|\ezsql\Database\ez_sqlite3|\ezsql\Database\ez_mysqli
*/
function database(string $sqlDriver = null, array $connectionSetting = null, string $instanceTag = null)
{
return Database::initialize($sqlDriver, $connectionSetting, $instanceTag);
}
/**
* Returns an already initialized database instance that was created with an tag.
*
* @param string $getTag - An stored tag instance
* @return \ezsql\Database\ez_pdo|\ezsql\Database\ez_pgsql|\ezsql\Database\ez_sqlsrv|\ezsql\Database\ez_sqlite3|\ezsql\Database\ez_mysqli
*/
function tagInstance(string $getTag = null)
{
return database($getTag);
}
/**
* Initialize an mysqli database.
*
* @param array $databaseSetting SQL connection parameters
* - [ `username`, `password`, `database`, host, port, charset ]
* @param string $instanceTag - Store the instance for later use
*
* @return \ezsql\Database\ez_mysqli
*/
function mysqlInstance(array $databaseSetting = null, string $instanceTag = null)
{
return database(\MYSQLI, $databaseSetting, $instanceTag);
}
/**
* Initialize an pgsql database.
*
* @param array $databaseSetting SQL connection parameters
* - [ `username`, `password`, `database`, host, port ]
* @param string $instanceTag - Store the instance for later use
*
* @return \ezsql\Database\ez_pgsql
*/
function pgsqlInstance(array $databaseSetting = null, string $instanceTag = null)
{
return database(\PGSQL, $databaseSetting, $instanceTag);
}
/**
* Initialize an mssql database.
*
* @param array $databaseSetting - SQL connection parameters
* @param string $instanceTag - Store the instance for later use
*
* @return \ezsql\Database\ez_sqlsrv
*/
function mssqlInstance(array $databaseSetting = null, string $instanceTag = null)
{
return database(\MSSQL, $databaseSetting, $instanceTag);
}
/**
* Initialize an pdo database.
*
* @param array $databaseSetting - SQL connection parameters
* @param string $instanceTag - Store the instance for later use
*
* @return \ezsql\Database\ez_pdo
*/
function pdoInstance(array $databaseSetting = null, string $instanceTag = null)
{
return database(\Pdo, $databaseSetting, $instanceTag);
}
/**
* Initialize an sqlite3 database.
*
* @param array $databaseSetting - SQL connection parameters
* @param string $instanceTag - Store the instance for later use
*
* @return \ezsql\Database\ez_sqlite3
*/
function sqliteInstance(array $databaseSetting = null, string $instanceTag = null)
{
return database(\SQLITE3, $databaseSetting, $instanceTag);
}
/**
* Returns database vendor string, either the global instance, or provided class instance.
* @param \ezsql\DatabaseInterface|null $instance
*
* @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv`
*/
function get_vendor(DatabaseInterface $instance = null)
{
return ezSchema::vendor($instance);
}
/**
* Convert array to string, and attach '`,`' for separation, if none is provided.
*
* @return string
*/
function to_string($arrays, $separation = ',')
{
return ezQuery::to_string($arrays, $separation);
}
/**
* Creates an database column as:
* - `column`, data`type`, ...value/options `arguments`.
*
* // datatype are global `CONSTANTS` and can be written out like:
* - VARCHAR, 32, notNULL, PRIMARY, SEQUENCE|AUTO, ....
* // SEQUENCE|AUTO constants will replaced with the proper auto sequence for the SQL driver
*
* @param string $column | `CONSTRAINT`, - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY
* @param string $type | constraintName, - data type for column/primary|foreign constraint name
* @param mixed ...$arguments any remainder assignments `ordered` like:
* - @param mixed $size, or/and
* - @param mixed $value, - or/and column should be `NULLS`|`notNULL`. If omitted, assumes `NULLS`
* - @param mixed $default, - or/and Optional. It is the value to assign to the column
* - @param mixed $autoNumber, or/and `AUTO` for vendor's auto numbering
* - @param mixed $primaryForeignKeys | or/and `PRIMARY`|`FOREIGN`
*
* @return string|bool - SQL schema string, or false for error
*/
function column(string $column = null, string $type = null, ...$arguments)
{
return ezSchema::column($column, $type, ...$arguments);
}
function primary(string $primaryName, ...$primaryKeys)
{
\array_unshift($primaryKeys, \PRIMARY);
return column(\CONSTRAINT, $primaryName, ...$primaryKeys);
}
function foreign(string $foreignName, ...$foreignKeys)
{
\array_unshift($foreignKeys, \FOREIGN);
return column(\CONSTRAINT, $foreignName, ...$foreignKeys);
}
function unique(string $uniqueName, ...$uniqueKeys)
{
\array_unshift($uniqueKeys, \UNIQUE);
return column(\CONSTRAINT, $uniqueName, ...$uniqueKeys);
}
function index(string $indexName, ...$indexKeys)
{
return column(\INDEX, $indexName, ...$indexKeys);
}
function addColumn(string $columnName, ...$datatype)
{
return column(\ADD, $columnName, ...$datatype);
}
function dropColumn(string $columnName, ...$data)
{
return column(\DROP, $columnName, ...$data);
}
function changingColumn(string $columnName, ...$datatype)
{
return column(\CHANGER, $columnName, ...$datatype);
}
/**
* Creates an equality comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function eq($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \EQ, $y, $and, ...$args);
return $expression;
}
/**
* Creates a non equality comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $operator, - One of
* '<', '>', '=', '!=', '>=', '<=', '<>', 'IN',, 'NOT IN', 'LIKE',
* 'NOT LIKE', 'BETWEEN', 'NOT BETWEEN', 'IS', 'IS NOT', or the constants above.
*
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* function comparison($x, $operator, $y, $and=null, ...$args)
* {
* return array($x, $operator, $y, $and, ...$args);
* }
*
* @return array
*/
function neq($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \NEQ, $y, $and, ...$args);
return $expression;
}
/**
* Creates the other non equality comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function ne($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \NE, $y, $and, ...$args);
return $expression;
}
/**
* Creates a lower-than comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function lt($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \LT, $y, $and, ...$args);
return $expression;
}
/**
* Creates a lower-than-equal comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function lte($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \LTE, $y, $and, ...$args);
return $expression;
}
/**
* Creates a greater-than comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function gt($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \GT, $y, $and, ...$args);
return $expression;
}
/**
* Creates a greater-than-equal comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function gte($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \GTE, $y, $and, ...$args);
return $expression;
}
/**
* Creates an IS NULL expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function isNull($x, $y = 'null', $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \_isNULL, $y, $and, ...$args);
return $expression;
}
/**
* Creates an IS NOT NULL expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function isNotNull($x, $y = 'null', $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \_notNULL, $y, $and, ...$args);
return $expression;
}
/**
* Creates a LIKE() comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function like($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \_LIKE, $y, $and, ...$args);
return $expression;
}
/**
* Creates a NOT LIKE() comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function notLike($x, $y, $and = null, ...$args)
{
$expression = array();
\array_push($expression, $x, \_notLIKE, $y, $and, ...$args);
return $expression;
}
/**
* Creates a IN () comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function in($x, $y, ...$args)
{
$expression = array();
\array_push($expression, $x, \_IN, $y, ...$args);
return $expression;
}
/**
* Creates a NOT IN () comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function notIn($x, $y, ...$args)
{
$expression = array();
\array_push($expression, $x, \_notIN, $y, ...$args);
return $expression;
}
/**
* Creates a BETWEEN () comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function between($x, $y, $y2, ...$args)
{
$expression = array();
\array_push($expression, $x, \_BETWEEN, $y, $y2, \_AND, ...$args);
return $expression;
}
/**
* Creates a NOT BETWEEN () comparison expression with the given arguments.
*
* @param strings $x, - The left expression.
* @param strings $y, - The right expression.
* @param strings $and, - combine additional expressions with, 'AND','OR', 'NOT', 'AND NOT'.
* @param strings $args - for any extras
*
* @return array
*/
function notBetween($x, $y, $y2, ...$args)
{
$expression = array();
\array_push($expression, $x, \_notBETWEEN, $y, $y2, \_AND, ...$args);
return $expression;
}
/**
* Sets the global class instance for functions to call class methods directly.
*
* @param ezQueryInterface|null $ezSQL
*
* @return boolean - `true`, or `false` for error
*/
function setInstance(ezQueryInterface $ezSQL = null)
{
global $ezInstance;
$status = false;
if ($ezSQL instanceof ezQueryInterface) {
$ezInstance = $ezSQL;
$status = true;
}
return $status;
}
/**
* Returns the global database class, last created instance or the one set with `setInstance()`.
*
* @return ezQueryInterface|null
*/
function getInstance()
{
global $ezInstance;
return ($ezInstance instanceof ezQueryInterface) ? $ezInstance : null;
}
/**
* Get multiple row result set from the database (previously cached results).
* Returns a multi dimensional array.
*
* Each element of the array contains one row of results and can be
* specified to be either an `object`, `json`, `associative array` or `numerical
* array`.
* - If no results are found then the function returns `false`,
* enabling you to use the function within logic statements such as if.
*
* **OBJECT** - `Returning results as an object` is the quickest way to get and
* display results. It is also useful that you are able to put
* `$object->var` syntax directly inside print statements without
* having to worry about causing php parsing errors.
*
* **ARRAY_A** - `Returning results as an associative array` is useful if you would
* like dynamic access to column names.
*
* **ARRAY_N** - `Returning results as a numerical array` is useful if you are using
* completely dynamic queries with varying column names but still need
* a way to get a handle on the results.
*
* **JSON** - `Returning results as JSON encoded` is useful for any interactive dynamic queries.
*
* @param constant $output Either: `OBJECT`|`ARRAY_A`|`ARRAY_N`|`JSON`
* @param object|null $instance `ez_pdo`|`ez_pgsql`|`ez_sqlsrv`|`ez_sqlite3`|`ez_mysqli`
* @return bool|object|array - results as objects (default)
*/
function get_results($output = \OBJECT, $instance = null)
{
$ezQuery = empty($instance) || !is_object($instance) ? getInstance() : $instance;
return ($ezQuery instanceof ezsqlModelInterface)
? $ezQuery->get_results(null, $output, false)
: false;
}
/**
* Clear/unset the global database class instance.
*/
function clearInstance()
{
global $ezInstance;
$GLOBALS['ezInstance'] = null;
$ezInstance = null;
unset($GLOBALS['ezInstance']);
}
/**
* Clean input string of XSS, html, javascript, etc...
* @param string $string
*
* @return string cleaned string
*/
function clean_string(string $string)
{
$patterns = array( // strip out:
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$string = \preg_replace($patterns, '', $string);
$string = \trim($string);
$string = \stripslashes($string);
return \htmlentities($string);
}
/**
* Check if path/filename is directory traversal attack.
*
* @param string $basePath base directory to check against
* @param string $filename will be preprocess with `sanitize_path()`
* @return boolean
*/
function is_traversal(string $basePath, string $filename)
{
if (\strpos(\urldecode($filename), '..') !== false)
return true;
$realBase = \rtrim(\realpath($basePath), _DS);
$userPath = $realBase . _DS . sanitize_path($filename);
$realUserPath = \realpath($userPath);
// Reassign with un-sanitized if file does not exits
if ($realUserPath === false)
$realUserPath = $filename;
return (\strpos($realUserPath, $realBase) !== 0);
}
/**
* Sanitize path to prevent directory traversal.
*
* Example:
*
* `sanitize_path("../../../../config.php-");`
* - Returns `config.php` without the path traversal
* @param string $path original file/path to be sanitized.
* @return string
*/
function sanitize_path(string $path)
{
$file = \preg_replace("/\.[\.]+/", "", $path);
$file = \preg_replace("/^[\/]+/", "", $file);
$file = \preg_replace("/^[A-Za-z][:\|][\/]?/", "", $file);
$file = \trim($file, '.-_');
return ($file);
}
/**
* Creates self signed certificate
*
* @param string $privatekeyFile
* @param string $certificateFile
* @param string $signingFile
* // param string $caCertificate
* @param string $ssl_path
* @param array $details - certificate details
*
* Example:
* array $details = [
* "countryName" => '',
* "stateOrProvinceName" => '',
* "localityName" => '',
* "organizationName" => '',
* "organizationalUnitName" => '',
* "commonName" => '',
* "emailAddress" => ''
* ];
*
* @return string certificate path
*/
function create_certificate(
string $privatekeyFile = 'certificate.key',
string $certificateFile = 'certificate.crt',
string $signingFile = 'certificate.csr',
// string $caCertificate = null,
string $ssl_path = null,
array $details = ["commonName" => "localhost"]
) {
if (empty($ssl_path)) {
$ssl_path = \getcwd();
$ssl_path = \preg_replace('/\\\/', \_DS, $ssl_path) . \_DS;
} else
$ssl_path = $ssl_path . \_DS;
$opensslConfig = array("config" => $ssl_path . 'openssl.cnf');
// Generate a new private (and public) key pair
$privatekey = \openssl_pkey_new($opensslConfig);
// Generate a certificate signing request
$csr = \openssl_csr_new($details, $privatekey, $opensslConfig);
// Create a self-signed certificate valid for 365 days
$sslcert = \openssl_csr_sign($csr, null, $privatekey, 365, $opensslConfig);
// Create key file. Note no passphrase
\openssl_pkey_export_to_file($privatekey, $ssl_path . $privatekeyFile, null, $opensslConfig);
// Create server certificate
\openssl_x509_export_to_file($sslcert, $ssl_path . $certificateFile, false);
// Create a signing request file
\openssl_csr_export_to_file($csr, $ssl_path . $signingFile);
return $ssl_path;
}
/**
* Preforms a `select` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
* Returns an `result` set, given the
* - column fields, conditions or conditional array.
*
* In the following format:
* ```php
* selecting(
* columns,
* innerJoin() | leftJoin() | rightJoin() | fullJoin(), // alias of joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition),
* where( eq( columns, values, _AND ), like( columns, _d ) ),
* groupBy( columns ),
* having( between( columns, values1, values2 ) ),
* orderBy( columns, desc ),
* limit( numberOfRecords, offset ),
* union(table, columnFields, conditions), // Returns an select SQL string with `UNION`
* unionAll(table, columnFields, conditions) // Returns an select SQL string with `UNION ALL`
*);
* ```
*
* @param mixed $columns fields, string or array
* @param mixed ...$conditions - of the following parameters:
*
* @param $joins, - `joining` clause (type, left table, right table, left column, right column, condition = EQ)
* - Either: `innerJoin()`, `leftJoin()`, `rightJoin()`, `fullJoin()`
* - Alias of: `joining(inner|left|right|full, leftTable, rightTable, leftColumn, rightColumn, equal condition)`
* @param $whereCondition, - `where` clause ( comparison(x, y, and) )
* @param $groupBy, - `groupBy` clause
* @param $having, - `having` clause ( comparison(x, y, and) )
* @param $orderby, - `orderby` clause for the query
* @param $limit, - `limit` clause the number of records
* @param $union/$unionAll - `union` clause combine the result sets and removes duplicate rows/does not remove
*
* @return mixed|object result set - see docs for more details, or false for error
*/
function selecting($columns = '*', ...$conditions)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->selecting($columns, ...$conditions)
: false;
}
/**
* Preforms a `insert` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Does an `insert` query with an array
* @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping)
* @return int|bool bool/id of inserted record, or false for error
*/
function inserting(array $keyValue)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->inserting($keyValue)
: false;
}
/**
* Preforms a `update` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Does an `update` query with an array, by conditional operator array
* @param array $keyValue, - table fields, assoc array with key = value (doesn't need escaped)
* @param mixed ...$whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)`
* - In the following format:
*```js
* eq('key/Field/Column', $value, _AND), // combine next expression
* neq('key/Field/Column', $value, _OR), // will combine next expression if
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
* lt('key/Field/Column', $value)
* lte('key/Field/Column', $value)
* gt('key/Field/Column', $value)
* gte('key/Field/Column', $value)
* isNull('key/Field/Column')
* isNotNull('key/Field/Column')
* like('key/Field/Column', '_%')
* notLike('key/Field/Column', '_%')
* in('key/Field/Column', $values)
* notIn('key/Field/Column', $values)
* between('key/Field/Column', $value, $value2)
* notBetween('key/Field/Column', $value, $value2)
*```
* @return mixed bool/results - false for error
*/
function updating(array $keyValue, ...$whereConditions)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->updating($keyValue, ...$whereConditions)
: false;
}
/**
* Preforms a `create` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Creates an database table with columns, by either:
*```js
* - array( column, datatype, ...value/options arguments ) // calls create_schema()
* - column( column, datatype, ...value/options arguments ) // returns string
* - primary( primary_key_label, ...primaryKeys) // returns string
* - foreign( foreign_key_label, ...foreignKeys) // returns string
* - unique( unique_key_label, ...uniqueKeys) // returns string
*```
* @param array ...$schemas An array of:
*
* - @param string `$column | CONSTRAINT,` - column name/CONSTRAINT usage for PRIMARY|FOREIGN KEY
* - @param string `$type | $constraintName,` - data type for column/primary | foreign constraint name
* - @param mixed `$size | ...$primaryForeignKeys,`
* - @param mixed `$value,` - column should be NULL or NOT NULL. If omitted, assumes NULL
* - @param mixed `$default` - Optional. It is the value to assign to the column
*
* @return mixed results of query() call
*/
function creating(...$schemas)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->creating(...$schemas)
: false;
}
/**
* Preforms a `delete` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Does an `delete` query with an array
* @param $table, - database table to access
* @param $whereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)`
* - In the following format:
*```js
* eq('key/Field/Column', $value, _AND), // combine next expression
* neq('key/Field/Column', $value, _OR), // will combine next expression if
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
* lt('key/Field/Column', $value)
* lte('key/Field/Column', $value)
* gt('key/Field/Column', $value)
* gte('key/Field/Column', $value)
* isNull('key/Field/Column')
* isNotNull('key/Field/Column')
* like('key/Field/Column', '_%')
* notLike('key/Field/Column', '_%')
* in('key/Field/Column', $values)
* notIn('key/Field/Column', $values)
* between('key/Field/Column', $value, $value2)
* notBetween('key/Field/Column', $value, $value2)
*```
* @return mixed bool/results - false for error
*/
function deleting(...$whereConditions)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->deleting(...$whereConditions)
: false;
}
/**
* Preforms a `replace` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Does an `replace` query with an array
* @param array $keyValue - table fields, assoc array with key = value (doesn't need escaping)
* @return mixed bool/id of replaced record, or false for error
*/
function replacing(array $keyValue)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->replacing($keyValue)
: false;
}
/**
* Preforms a `drop` method call on a already preset `table name`, and optional `prefix`
*
* This function **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Does an `drop` table query if table exists.
*
* @return bool|int
*/
function dropping()
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->dropping()
: false;
}
/**
* Preforms a `alter` method call on a already preset `table name`, and optional `prefix`
*
* This method **expects** either `table_setup(name, prefix)`, `set_table(name)`, or `set_prefix(append)`
* to have been called **before usage**, otherwise will return `false`, if no `table name` previous stored.
*
* Modify columns in an existing database table, by either:
*```js
* - array( column_name, datatype, ...value/options arguments ) // calls create_schema()
* - addColumn( column_name, datatype, ...value/options arguments ) // returns string
* - dropColumn( column_name ) // returns string
* - changingColumn( column_name, datatype, ...value/options arguments ) // returns string
*```
* @param array ...$alteringSchema An array of:
*
* - @param string `$name,` - column name
* - @param string `$type,` - data type for the column
* - @param mixed `$size,` | `$value,`
* - @param mixed `...$anyOtherArgs`
*
* @return mixed results of query() call
*/
function altering(...$alteringSchema)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->altering(...$alteringSchema)
: false;
}
/**
* Set table `name` and `prefix` for usage on calls to database `CRUD`
* **method/function** *names* ending with `ing`.
*
* @param string $name
* @param string $prefix
*/
function table_setup(string $name = '', string $prefix = '')
{
$ezQuery = getInstance();
if (!$ezQuery instanceof ezsqlModelInterface)
return false;
$ezQuery->tableSetup($name, $prefix);
}
/**
* Set table `name` to use on calls to database `CRUD` **method/function** *names* ending with `ing`.
*
* @param string $name
*/
function set_table(string $name = '')
{
$ezQuery = getInstance();
if (!$ezQuery instanceof ezsqlModelInterface)
return false;
$ezQuery->setTable($name);
}
/**
* Add a `prefix` to **append** to `table` name on calls to database `CRUD`
* **method/function** *names* ending with `ing`.
*
* @param string $append
*/
function set_prefix(string $append = '')
{
$ezQuery = getInstance();
if (!$ezQuery instanceof ezsqlModelInterface)
return false;
$ezQuery->setPrefix($append);
}
/**
* Does an `select into` statement by calling `select` method
* @param string $newTable, - new database table to be created
* @param mixed $fromColumns - the columns from old database table
* @param string $oldTable - old database table
* @param mixed $fromWhereConditions, - where clause `eq(x, y, _AND), another clause - same as array(x, =, y, and, extra)`
* - In the following format:
*```js
* eq('key/Field/Column', $value, _AND), // combine next expression
* neq('key/Field/Column', $value, _OR), // will combine next expression if
* ne('key/Field/Column', $value), // the default is _AND so will combine next expression
* lt('key/Field/Column', $value)
* lte('key/Field/Column', $value)
* gt('key/Field/Column', $value)
* gte('key/Field/Column', $value)
* isNull('key/Field/Column')
* isNotNull('key/Field/Column')
* like('key/Field/Column', '_%')
* notLike('key/Field/Column', '_%')
* in('key/Field/Column', $values)
* notIn('key/Field/Column', $values)
* between('key/Field/Column', $value, $value2)
* notBetween('key/Field/Column', $value, $value2)
*```
* @return mixed bool/result - false for error
* @codeCoverageIgnore
*/
function select_into(string $newTable, $fromColumns = '*', string $oldTable = null, ...$fromWhereConditions)
{
$ezQuery = getInstance();
return ($ezQuery instanceof DatabaseInterface)
? $ezQuery->select_into($newTable, $fromColumns, $oldTable, ...$fromWhereConditions)
: false;
}