Skip to content

Commit fc9797e

Browse files
committed
Merge branch 'master' into v5
1 parent 669c438 commit fc9797e

21 files changed

Lines changed: 919 additions & 298 deletions

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[![Total Downloads](https://poser.pugx.org/ezsql/ezsql/downloads)](https://packagist.org/packages/ezsql/ezsql)
1010

1111
***A class to make it very easy to deal with database connections.***
12+
*An universal interchangeable **CRUD** system.*
1213

1314
This is [__Version 5__](https://github.com/ezSQL/ezsql/tree/v5) which will break users of **version 4**.
1415

@@ -34,6 +35,9 @@ Mainly by:
3435
- The table *name* with *prefix*, can be preset/stored with methods `tableSetup(name, prefix), or setTable(name), setPrefix(append)`, if called without presetting, `false` is returned.
3536
- This **feature** will be added to **all** database *CRUD* access methods , each method name will have an `ing` ending added.
3637
- Removed global functions where `table` name passed in, use functions using preset table names ending with `ing`.
38+
- renamed cleanInput to clean_string
39+
- renamed createCertificate to create_certificate
40+
- added global get_results to return result sets in different formats
3741

3842
[__Version 4__](https://github.com/ezSQL/ezsql/tree/v4) has many modern programming practices in which will break users of version 3.
3943

@@ -83,7 +87,7 @@ ___General Methods___
8387
string $path = '.'._DS
8488
);
8589
secureReset();
86-
createCertificate(string $privatekeyFile = certificate.key,
90+
create_certificate(string $privatekeyFile = certificate.key,
8791
string $certificateFile = certificate.crt,
8892
string $signingFile = certificate.csr,
8993
string $ssl_path = null, array $details = [commonName => localhost]
@@ -96,6 +100,7 @@ ___Shortcut Table Methods___
96100
primary(string $primaryName, ...$primaryKeys);
97101
index(string $indexName, ...$indexKeys);
98102
drop(string $table);
103+
99104
Example
100105

101106
```php
@@ -147,6 +152,9 @@ prepareOff(); // When off shortcut SQL Methods calls will use vendors escape rou
147152
* `delete(string $table = null, ...$whereConditions);`
148153
* `replace(string $table = null, $keyAndValue);`
149154
* `insert(string $table = null, $keyAndValue);`
155+
* `create(string $table = null, ...$schemas);`
156+
* `drop(string $table = null);`
157+
* `alter(string $table = null, ...$alteringSchema);`
150158
* `insert_select(string $toTable = null, $toColumns = '*', $fromTable = null, $fromColumns = '*', ...$conditions);`
151159

152160
```php
@@ -239,6 +247,9 @@ $result = $db->select('profile', 'name, email',
239247
foreach ($result as $row) {
240248
echo $row->name.' '.$row->email;
241249
}
250+
251+
// To get results in `JSON` format
252+
$json = get_results(JSON, $db);
242253
```
243254

244255
#### Example for using prepare statements directly, no shortcut SQL methods used
@@ -247,7 +258,9 @@ foreach ($result as $row) {
247258
$db->query_prepared('INSERT INTO profile( name, email, phone) VALUES( ?, ?, ? );', [$user, $address, $number]);
248259

249260
$db->query_prepared('SELECT name, email FROM profile WHERE phone = ? OR id != ?', [$number, 5]);
250-
$result = $db->queryResult(); // the last query that has results are stored in `last_result` protected property
261+
$result = $db->queryResult(); // the last query that has results are stored in `lastResult` protected property
262+
// Or for results in other formats use the global function, will use global database instance if no `$db` supplied
263+
$result = get_results(/* OBJECT|ARRAY_A|ARRAY_N|JSON */, $db); // Defaults to `OBJECT`
251264

252265
foreach ($result as $row) {
253266
echo $row->name.' '.$row->email;
@@ -271,11 +284,11 @@ use function ezsql\functions\{
271284
setInstance,
272285
getInstance,
273286
clearInstance,
287+
get_vendor,
274288
///
275-
getVendor,
276289
to_string,
277-
cleanInput,
278-
createCertificate,
290+
clean_string,
291+
create_certificate,
279292
///
280293
column,
281294
primary,
@@ -284,6 +297,7 @@ use function ezsql\functions\{
284297
index,
285298
addColumn,
286299
dropColumn,
300+
changingColumn,
287301
///
288302
eq,
289303
neq,
@@ -301,9 +315,6 @@ use function ezsql\functions\{
301315
between,
302316
notBetween,
303317
///
304-
select_into,
305-
insert_select,
306-
create_select,
307318
where,
308319
grouping,
309320
groupBy,
@@ -323,9 +334,14 @@ use function ezsql\functions\{
323334
replacing,
324335
selecting,
325336
inserting,
337+
altering,
338+
get_results,
326339
table_setup,
327340
set_table,
328-
set_prefix
341+
set_prefix,
342+
select_into,
343+
insert_select,
344+
create_select,
329345
};
330346
```
331347

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"name": "ezsql/ezsql",
3-
"description": "Advance database access library. Make interacting with a database ridiculously easy.",
3+
"description": "Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.",
44
"keywords": [
5+
"crud",
6+
"dba",
57
"mysql",
68
"mysqli",
79
"postgresql",
@@ -13,8 +15,7 @@
1315
"sqlite3",
1416
"database",
1517
"abstraction",
16-
"sql",
17-
"dba"
18+
"sql"
1819
],
1920
"license": [
2021
"LGPL-3.0-or-later",

lib/Config.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,6 @@ public function __construct(string $driver = '', array $arguments = null)
3131
}
3232
}
3333

34-
/**
35-
* Setup Connections for each SQL database class
36-
* @param string $driver - The vendor's SQL database driver name
37-
* @param string|array $arguments In the following:
38-
*
39-
* - user|args[0][1] // The database user name
40-
* - password|args[1][2] // The database users password
41-
* - database|args[1][2] // The name of the database
42-
* - host|args[3] // The host name or IP address of the database server,
43-
* Default is localhost
44-
* - port|args[4] // The database TCP/IP port,
45-
* Default is: 5432 - PostgreSQL, 3306 - MySQL
46-
*
47-
* for: mysqli
48-
* - (username, password, database, host, port, charset)
49-
* - charset|args[5] // The database charset,
50-
* Default is empty string
51-
*
52-
* for: postgresql
53-
* - (username, password, database, host, port)
54-
*
55-
* for: sqlserver
56-
* - (username, password, database, host, convertMysqlToMssqlQuery)
57-
* - convertMysqlToMssqlQuery[4] // convert Queries in MySql syntax to MS-SQL syntax
58-
* Default is false
59-
*
60-
* for: pdo
61-
* - (dsn, username, password, options, isFile?)
62-
* - dsn |args[0] // The PDO DSN connection parameter string
63-
* - options|args[3] // Array for setting connection options as MySQL
64-
* - isFile|args[4] // File based databases like SQLite don't need
65-
* user and password, they work with path in the dsn parameter
66-
* Default is false
67-
*
68-
* for: sqlite3
69-
* - (filePath, database) - filePath|args[0] // The path to open an SQLite database
70-
*/
7134
public static function initialize(string $driver = '', array $arguments = null)
7235
{
7336
return new self($driver, $arguments);

lib/ConfigAbstract.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,66 @@
2424
namespace ezsql;
2525

2626
/**
27-
* @method set/get{property} - a property that needs to be accessed
2827
*
2928
* @method void setDriver($args);
29+
* Database Sql driver name
3030
* @method void setDsn($args);
31+
* The PDO connection parameter string, database server in the DSN parameters
3132
* @method void setUser($args);
33+
* Database user name
3234
* @method void setPassword($args);
35+
* Database password for the given user
3336
* @method void setName($args);
37+
* Database name
3438
* @method void setHost($args);
39+
* Host name or IP address
3540
* @method void setPort($args);
41+
* TCP/IP port of PostgreSQL/MySQL
3642
* @method void setCharset($args);
43+
* Database charset
3744
* @method void setOptions($args);
45+
* The PDO array for connection options, MySQL connection charset, for example
3846
* @method void setIsFile($args);
47+
* Check PDO for whether it is a file based database connection, for example to a SQLite
48+
* database file, or not
3949
* @method void setToMssql($args);
50+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
51+
* Yes, there are some differences in query syntax.
4052
* @method void setToMysql($args);
53+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
54+
* Yes, there are some differences in query syntax.
4155
* @method void setPath($args);
56+
* The path to open an SQLite database
4257
*
4358
* @method string getDriver();
59+
* Database Sql driver name
4460
* @method string getDsn();
61+
* The PDO connection parameter string, database server in the DSN parameters
4562
* @method string getUser();
63+
* Database user name
4664
* @method string getPassword()
65+
* Database password for the given user
4766
* @method string getName();
67+
* Database name
4868
* @method string getHost();
69+
* Host name or IP address
4970
* @method string getPort();
71+
* TCP/IP port of PostgreSQL/MySQL
5072
* @method string getCharset();
73+
* Database charset
5174
* @method string getOptions();
75+
* The PDO array for connection options, MySQL connection charset, for example
5276
* @method string getToMysql();
77+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
78+
* Yes, there are some differences in query syntax.
5379
* @method bool getIsFile();
80+
* Check PDO for whether it is a file based database connection, for example to a SQLite
81+
* database file, or not
5482
* @method bool getToMssql();
83+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
84+
* Yes, there are some differences in query syntax.
5585
* @method string getPath();
86+
* The path to open an SQLite database
5687
*/
5788
abstract class ConfigAbstract
5889
{

lib/ConfigInterface.php

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,100 @@
44

55
/**
66
* @method void setDriver($args);
7+
* Database Sql driver name
78
* @method void setDsn($args);
9+
* The PDO connection parameter string, database server in the DSN parameters
810
* @method void setUser($args);
11+
* Database user name
912
* @method void setPassword($args);
13+
* Database password for the given user
1014
* @method void setName($args);
15+
* Database name
1116
* @method void setHost($args);
17+
* Host name or IP address
1218
* @method void setPort($args);
19+
* TCP/IP port of PostgreSQL/MySQL
1320
* @method void setCharset($args);
21+
* Database charset
1422
* @method void setOptions($args);
23+
* The PDO array for connection options, MySQL connection charset, for example
1524
* @method void setIsFile($args);
25+
* Check PDO for whether it is a file based database connection, for example to a SQLite
26+
* database file, or not
1627
* @method void setToMssql($args);
28+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
29+
* Yes, there are some differences in query syntax.
1730
* @method void setToMysql($args);
31+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
32+
* Yes, there are some differences in query syntax.
1833
* @method void setPath($args);
34+
* The path to open an SQLite database
1935
*
2036
* @method string getDriver();
37+
* Database Sql driver name
2138
* @method string getDsn();
39+
* The PDO connection parameter string, database server in the DSN parameters
2240
* @method string getUser();
41+
* Database user name
2342
* @method string getPassword()
43+
* Database password for the given user
2444
* @method string getName();
45+
* Database name
2546
* @method string getHost();
47+
* Host name or IP address
2648
* @method string getPort();
49+
* TCP/IP port of PostgreSQL/MySQL
2750
* @method string getCharset();
51+
* Database charset
2852
* @method string getOptions();
53+
* The PDO array for connection options, MySQL connection charset, for example
2954
* @method bool getIsFile();
30-
* @method bool getToMysql();
55+
* Check PDO for whether it is a file based database connection, for example to a SQLite
56+
* database file, or not
3157
* @method bool getToMssql();
58+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
59+
* Yes, there are some differences in query syntax.
60+
* @method bool getToMysql();
61+
* If we want to convert Queries in MySql syntax to MS-SQL syntax.
62+
* Yes, there are some differences in query syntax.
3263
* @method string getPath();
64+
* The path to open an SQLite database
3365
*/
3466
interface ConfigInterface
3567
{
3668
/**
3769
* Setup Connections for each SQL database class
3870
*
39-
* @param string $driver
40-
* @param string|array $arguments
71+
* @param string $driver - The vendor's SQL database driver name
72+
* @param array $arguments SQL connection parameters, in the following:
73+
*```js
74+
* [
75+
* user, // The database user name.
76+
* password, // The database users password.
77+
* database, // The name of the database.
78+
* host, // The host name or IP address of the database server. Default is localhost
79+
* port // The database TCP/IP port. Default is: 5432 - PostgreSQL, 3306 - MySQL
80+
* ]
81+
*```
82+
* for: **mysqli** - (`username`, `password`, `database`, `host`, `port`, `charset`)
83+
* - `charset` // The database charset,
84+
* Default is empty string
85+
*
86+
* for: **postgresql** - (`username`, `password`, `database`, `host`, `port`)
87+
*
88+
* for: **sqlserver** - (`username`, `password`, `database`, `host`, `convertMysqlToMssqlQuery`)
89+
* - `convertMysqlToMssqlQuery` // convert Queries in MySql syntax to MS-SQL syntax
90+
* Default is false
91+
*
92+
* for: **pdo** - (`dsn`, `username`, `password`, `options`, `isFile`?)
93+
* - `dsn` // The PDO DSN connection parameter string
94+
* - `options` // Array for setting connection options as MySQL
95+
* - `isFile` // File based databases like SQLite don't need
96+
* user and password, they work with path in the dsn parameter
97+
* Default is false
98+
*
99+
* for: **sqlite3** - (`filePath`, `database`)
100+
* - `filePath` // The path to open an SQLite database
41101
*/
42102
public static function initialize(string $driver = '', array $arguments = null);
43103
}

lib/Constants.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
/**
66
* ezsqlModel Constants
77
*/
8-
\defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.0.0');
8+
\defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.1.0');
99
\defined('OBJECT') or \define('OBJECT', 'OBJECT');
1010
\defined('ARRAY_A') or \define('ARRAY_A', 'ARRAY_A');
1111
\defined('ARRAY_N') or \define('ARRAY_N', 'ARRAY_N');
12+
// Use to set get_result output as json
13+
\define('JSON', 'json');
1214

1315
// Error messages
1416
\define('MISSING_CONFIGURATION', '<b>Fatal Error:</b> Missing configuration details to connect to database');
@@ -17,8 +19,6 @@
1719

1820
// ezQuery prepare placeholder/positional tag
1921
\define('_TAG', '__ez__');
20-
// Use to set get_result output as json
21-
\define('_JSON', 'json');
2222

2323
/**
2424
* Operator boolean expressions.
@@ -174,7 +174,7 @@
174174
\define('DROP', 'DROP COLUMN');
175175
\define('CHANGE', 'CHANGE COLUMN');
176176
\define('ALTER', 'ALTER COLUMN');
177-
\define('MODIFY', 'MODIFY');
177+
\define('MODIFY', 'MODIFY COLUMN');
178178
\define('RENAME', 'RENAME TO');
179179
\define('CHANGER', '__modifyingColumns__');
180180

0 commit comments

Comments
 (0)