Skip to content

Commit 40307b5

Browse files
committed
corrections/updates, additional function, and renaming
1 parent d5668fd commit 40307b5

File tree

8 files changed

+66
-28
lines changed

8 files changed

+66
-28
lines changed

README.md

Lines changed: 19 additions & 6 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
@@ -273,7 +284,7 @@ use function ezsql\functions\{
273284
setInstance,
274285
getInstance,
275286
clearInstance,
276-
getVendor,
287+
get_vendor,
277288
///
278289
to_string,
279290
clean_string,
@@ -286,6 +297,7 @@ use function ezsql\functions\{
286297
index,
287298
addColumn,
288299
dropColumn,
300+
changingColumn,
289301
///
290302
eq,
291303
neq,
@@ -303,9 +315,6 @@ use function ezsql\functions\{
303315
between,
304316
notBetween,
305317
///
306-
select_into,
307-
insert_select,
308-
create_select,
309318
where,
310319
grouping,
311320
groupBy,
@@ -325,10 +334,14 @@ use function ezsql\functions\{
325334
replacing,
326335
selecting,
327336
inserting,
337+
altering,
328338
get_results,
329339
table_setup,
330340
set_table,
331-
set_prefix
341+
set_prefix,
342+
select_into,
343+
insert_select,
344+
create_select,
332345
};
333346
```
334347

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/ezFunctions.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ function sqliteInstance(array $databaseSetting = null, string $instanceTag = nul
133133
}
134134

135135
/**
136-
* Returns the current global database vendor being used.
136+
* Returns database vendor string, either the global instance, or provided class instance.
137+
* @param \ezsql\DatabaseInterface|null $instance
137138
*
138139
* @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv`
139140
*/
140-
function getVendor()
141+
function get_vendor(DatabaseInterface $instance = null)
141142
{
142-
return ezSchema::vendor();
143+
return ezSchema::vendor($instance);
143144
}
144145

145146
/**
@@ -209,6 +210,11 @@ function dropColumn(string $columnName, ...$data)
209210
return column(\DROP, $columnName, ...$data);
210211
}
211212

213+
function changingColumn(string $columnName, ...$datatype)
214+
{
215+
return column(\CHANGER, $columnName, ...$datatype);
216+
}
217+
212218
/**
213219
* Creates self signed certificate
214220
*

lib/ezQuery.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use ezsql\ezSchema;
66
use ezsql\ezQueryInterface;
7-
use function ezsql\functions\{column, getVendor};
7+
use function ezsql\functions\{column, get_vendor};
88

99
class ezQuery implements ezQueryInterface
1010
{
@@ -896,7 +896,7 @@ private function create_schema(array ...$columnDataOptions)
896896

897897
public function create(string $table = null, ...$schemas)
898898
{
899-
$vendor = getVendor();
899+
$vendor = get_vendor();
900900
if (empty($table) || empty($schemas) || empty($vendor))
901901
return false;
902902

lib/ezSchema.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,15 @@ public function __call($type, $args)
158158
}
159159

160160
/**
161-
* Returns the current global database vendor being used.
161+
* Returns database vendor string, either the global instance, or provided database class.
162+
* @param \ezsql\DatabaseInterface|null $db
162163
*
163164
* @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv`
164165
*/
165-
public static function vendor()
166+
public static function vendor(DatabaseInterface $db = null)
166167
{
167168
$type = null;
168-
$instance = getInstance();
169+
$instance = empty($db) || !is_object($db) ? getInstance() : $db;
169170
if ($instance instanceof DatabaseInterface) {
170171
$type = $instance->settings()->getDriver();
171172
if ($type === \Pdo) {

lib/ezsqlModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use ezsql\ezQuery;
66
use ezsql\ezsqlModelInterface;
7-
use function ezsql\functions\{getVendor, create_certificate};
7+
use function ezsql\functions\{get_vendor, create_certificate};
88

99
/**
1010
* Core class containing common functions to manipulate **query** `result sets` once returned.
@@ -855,7 +855,7 @@ public function secureSetup(
855855
string $path = '.' . \_DS
856856
) {
857857
if (!\file_exists($path . $cert) || !\file_exists($path . $key)) {
858-
$vendor = getVendor();
858+
$vendor = get_vendor();
859859
if (($vendor != \SQLITE) || ($vendor != \MSSQL))
860860
$path = create_certificate();
861861
} elseif ($path == '.' . \_DS) {

tests/ezFunctionsTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
setInstance,
99
getInstance,
1010
clearInstance,
11-
getVendor,
11+
get_vendor,
1212
column,
1313
primary,
1414
foreign,
1515
unique,
1616
index,
1717
addColumn,
1818
dropColumn,
19+
changingColumn,
1920
eq,
2021
neq,
2122
ne,
@@ -45,6 +46,8 @@
4546
replacing,
4647
selecting,
4748
inserting,
49+
altering,
50+
get_results,
4851
table_setup,
4952
set_table,
5053
set_prefix
@@ -64,7 +67,7 @@ public function testGetInstance()
6467

6568
public function testGetVendor()
6669
{
67-
$this->assertNull(getVendor());
70+
$this->assertNull(get_vendor());
6871
}
6972

7073
public function testColumn()
@@ -101,6 +104,10 @@ public function testDropColumn()
101104
{
102105
$this->assertFalse(dropColumn('column', 'column'));
103106
}
107+
public function testChangingColumn()
108+
{
109+
$this->assertFalse(changingColumn('column', 'column'));
110+
}
104111

105112
public function testEq()
106113
{
@@ -269,6 +276,16 @@ public function testReplacing()
269276
$this->assertFalse(replacing(['data' => 'data2']));
270277
}
271278

279+
public function testAltering()
280+
{
281+
$this->assertFalse(altering([]));
282+
}
283+
284+
public function testGet_results()
285+
{
286+
$this->assertFalse(get_results());
287+
}
288+
272289
public function testDropping()
273290
{
274291
$this->assertFalse(dropping());

tests/ezSchemaTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
mssqlInstance,
1212
sqliteInstance,
1313
clearInstance,
14-
getVendor,
14+
get_vendor,
1515
column,
1616
primary,
1717
index
@@ -22,7 +22,7 @@ class ezSchemaTest extends EZTestCase
2222
public function testVendor()
2323
{
2424
clearInstance();
25-
$this->assertEquals(null, getVendor());
25+
$this->assertEquals(null, get_vendor());
2626
$this->assertEquals(false, ezSchema::datatype(BLOB, NULLS));
2727
$this->assertFalse(column('id', INTR, 32, AUTO, PRIMARY));
2828
}
@@ -36,7 +36,7 @@ public function testVendor_mysqli()
3636
}
3737

3838
mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
39-
$this->assertEquals(MYSQLI, getVendor());
39+
$this->assertEquals(MYSQLI, get_vendor());
4040
$this->assertEquals('BLOB NULL', ezSchema::datatype(BLOB, NULLS));
4141
$this->assertEquals('VARCHAR(256) NOT NULL', ezSchema::datatype(VARCHAR, 256, notNULL));
4242
$this->assertEquals('id INT(32) AUTO_INCREMENT PRIMARY KEY, ', column('id', INTR, 32, AUTO, PRIMARY));
@@ -129,7 +129,7 @@ public function testVendor_Pgsql()
129129
}
130130

131131
pgsqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME, self::TEST_DB_HOST, self::TEST_DB_PORT]);
132-
$this->assertEquals(PGSQL, getVendor());
132+
$this->assertEquals(PGSQL, get_vendor());
133133
$this->assertEquals('TIMESTAMP NOT NULL', ezSchema::datatype(TIMESTAMP, notNULL));
134134
$this->assertEquals('price NUMERIC(6,2) NULL, ', column('price', NUMERIC, 6, 2, NULLS));
135135
$this->assertEquals('id SERIAL PRIMARY KEY, ', column('id', AUTO, PRIMARY));
@@ -144,7 +144,7 @@ public function testVendor_Sqlite3()
144144
}
145145

146146
sqliteInstance([self::TEST_SQLITE_DB_DIR, self::TEST_SQLITE_DB]);
147-
$this->assertEquals(SQLITE3, getVendor());
147+
$this->assertEquals(SQLITE3, get_vendor());
148148
}
149149

150150
public function testVendor_Sqlsrv()
@@ -156,7 +156,7 @@ public function testVendor_Sqlsrv()
156156
}
157157

158158
mssqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]);
159-
$this->assertEquals(MSSQL, getVendor());
159+
$this->assertEquals(MSSQL, get_vendor());
160160
}
161161

162162
public function testVendor_Pdo()
@@ -169,7 +169,7 @@ public function testVendor_Pdo()
169169

170170
$pdo_mysql = pdoInstance(['mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=3306', self::TEST_DB_USER, self::TEST_DB_PASSWORD]);
171171
$pdo_mysql->connect();
172-
$this->assertEquals(MYSQLI, getVendor());
172+
$this->assertEquals(MYSQLI, get_vendor());
173173
}
174174

175175
public function test__construct()

0 commit comments

Comments
 (0)