Skip to content

Commit 8094365

Browse files
committed
Merge branch 'master' into newmaster
2 parents b0c9902 + 2992d2f commit 8094365

23 files changed

+4404
-586
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ clover.xml
88
*.sqlite3
99
vendor
1010
build/logs/clover.xml
11-
tests/pdo/ez_test.sqlite
12-
tests/sqlite/ez_test.sqlite
13-
tests/sqlite/ez_test.sqlite3
1411
.vscode/settings.json
1512
*.crt
1613
*.csr

CONTRIBUTORS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
**ezSQL** *Contributors*
2+
============================================
3+
4+
* **[Justin Vincent](http://twitter.com/justinvincent)**
5+
6+
* Author: ezSQL class - *mySQL, PDO, PostgreSQL, Cubrid, Oracle8_9*
7+
8+
* **[Stefanie Janine Stoelting](https://stefanie-stoelting.de)**
9+
10+
* Author:
11+
- *ezSQL version 3.00*
12+
- *oracleTNS*
13+
- *phpunit tests*
14+
- *RecordSet - for working with query results*
15+
16+
* **davisjw**
17+
18+
* Author: ezSQL class - *Sqlserver*
19+
20+
* **Silvio Wanka**
21+
* Author: ezSQL class - *sqlite3*
22+
23+
----
24+
25+
**[L. Stubbs]**
26+
27+
* Author/Maintainer:
28+
- ezSQL version 3
29+
- In Development version *4.0*
30+
- *ezQuery, ezFunctions, ezSchema*
31+
32+
----
33+
34+
**[Full contributors list.](https://github.com/ezsql/ezsql/contributors)**

cacert.pem

Lines changed: 3401 additions & 0 deletions
Large diffs are not rendered by default.

lib/ez_sql_mysqli.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
<?php
2-
/**
3-
* ezSQL Database specific class - mySQL
4-
* Desc..: mySQL component (part of ezSQL databse abstraction library)
5-
*
6-
* @author Justin Vincent ([email protected])
7-
* @author Stefanie Janine Stoelting <[email protected]>
8-
* Contributor: Lawrence Stubbs <[email protected]>
9-
* @link http://twitter.com/justinvincent
10-
* @name ezSQL_mysql
11-
* @package ezSQL
12-
* @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
13-
*
14-
*/
152

163
class ezSQL_mysqli extends ezSQLcore
174
{
@@ -78,8 +65,11 @@ class ezSQL_mysqli extends ezSQLcore
7865
*/
7966
public $dbh;
8067

81-
protected $preparedvalues = [];
68+
protected $preparedValues = [];
8269

70+
private static $isSecure = false;
71+
private static $secure = null;
72+
8373
/**
8474
* Constructor - allow the user to perform a quick connect at the same time
8575
* as initializing the ezSQL_mysql class

lib/ez_sql_pdo.php

Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11
<?php
2-
/**
3-
* ezSQL class - PDO
4-
* Desc..: PDO component (part of ezSQL database abstraction library)
5-
*
6-
* @author Justin Vincent ([email protected])
7-
* @author Stefanie Janine Stoelting <[email protected]>
8-
* Contributor: Lawrence Stubbs <[email protected]>
9-
* @link http://twitter.com/justinvincent
10-
* @name ezSQL_pdo
11-
* @package ezSQL
12-
* @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
13-
*
14-
*/
152

163
class ezSQL_pdo extends ezSQLcore
174
{
@@ -47,26 +34,30 @@ class ezSQL_pdo extends ezSQLcore
4734
* The array for connection options, MySQL connection charset, for example
4835
* @var array
4936
*/
50-
private $_options;
37+
private static $_options = array();
5138

5239
/**
5340
* Whether it is a file based database connection, for example to a SQLite
5441
* database file, or not
5542
* @var boolean Default is false
5643
*/
57-
private $_isFileBased=false;
44+
private $_isFileBased = false;
45+
46+
private static $isSecure = false;
47+
private static $secure = null;
48+
private $dbh;
5849

5950
/**
6051
* Show errors
6152
* @var boolean Default is true
6253
*/
6354
public $show_errors = true;
6455

65-
protected $preparedvalues = array();
56+
protected $preparedValues = array();
6657

6758
/**
68-
* Constructor - allow the user to perform a qucik connect at the same time
69-
* as initialising the ezSQL_sqlite class
59+
* Constructor - allow the user to perform a quick connect at the same time
60+
* as initializing the ezSQL_sqlite class
7061
*
7162
* @param string $dsn The connection parameter string
7263
* Default is empty string
@@ -82,12 +73,13 @@ class ezSQL_pdo extends ezSQLcore
8273
* dsn parameter
8374
* Default is false
8475
*/
85-
public function __construct($dsn='', $user='', $password='', $options=array(), $isFileBased=false) {
76+
public function __construct($dsn = '', $user = '', $password = '', $options = array(), $isFileBased = false)
77+
{
8678
if ( ! \class_exists ('PDO') ) {
87-
throw new Exception('<b>Fatal Error:</b> ezSQL_pdo requires PDO Lib to be compiled and or linked in to the PHP engine');
79+
throw new \Exception('<b>Fatal Error:</b> ezSQL_pdo requires PDO Lib to be compiled and or linked in to the PHP engine');
8880
}
8981
if ( ! \class_exists ('ezSQLcore') ) {
90-
throw new Exception('<b>Fatal Error:</b> ezSQL_pdo requires ezSQLcore (ez_sql_core.php) to be included/loaded before it can be used');
82+
throw new \Exception('<b>Fatal Error:</b> ezSQL_pdo requires ezSQLcore (ez_sql_core.php) to be included/loaded before it can be used');
9183
}
9284

9385
parent::__construct();
@@ -103,6 +95,33 @@ public function __construct($dsn='', $user='', $password='', $options=array(), $
10395
\setQuery($this);
10496
} // __construct
10597

98+
public static function securePDO(
99+
$vendor = null,
100+
$key = 'certificate.key',
101+
$cert = 'certificate.crt',
102+
$ca = 'cacert.pem',
103+
$path = '.'.\_DS)
104+
{
105+
if (\array_key_exists(\strtolower($vendor), \VENDOR)
106+
&& (! \file_exists($path.$cert) || ! \file_exists($path.$key)))
107+
ezQuery::createCertificate();
108+
109+
if (($vendor == 'pgsql') || ($vendor == 'postgresql')) {
110+
self::$secure = "sslmode=require;sslcert=".$path.$cert.";sslkey=".$path.$key.";sslrootcert=".$path.$ca.";";
111+
self::$isSecure = true;
112+
} elseif (($vendor == 'mysql') || ($vendor == 'mysqli')) {
113+
self::$_options = array(
114+
\PDO::MYSQL_ATTR_SSL_KEY => $path.$key,
115+
\PDO::MYSQL_ATTR_SSL_CERT => $path.$cert,
116+
\PDO::MYSQL_ATTR_SSL_CA => $path.$ca,
117+
\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
118+
);
119+
} elseif (($vendor == 'sqlserver') || ($vendor == 'mssql') || ($vendor == 'sqlsrv')) {
120+
self::$secure = ";Encrypt=true;TrustServerCertificate=true";
121+
self::$isSecure = true;
122+
}
123+
}
124+
106125
/**
107126
* Try to connect to the database server in the DSN parameters
108127
*
@@ -121,16 +140,21 @@ public function __construct($dsn='', $user='', $password='', $options=array(), $
121140
* Default is false
122141
* @return boolean
123142
*/
124-
public function connect($dsn='', $dbuser='', $dbpassword='', $options=array(), $isFileBased=false) {
143+
public function connect($dsn = '', $dbuser = '', $dbpassword = '', $options = array(), $isFileBased = false)
144+
{
125145
$this->_connected = false;
126146

127-
$this->_dsn = empty($dsn) ? $this->_dsn : $dsn;
147+
if (self::$isSecure)
148+
$this->_dsn = empty($dsn) ? $this->_dsn.$this->secure : $dsn.$this->secure;
149+
else
150+
$this->_dsn = empty($dsn) ? $this->_dsn : $dsn;
151+
128152
$this->_isFileBased = $isFileBased;
129153

130154
if (!$isFileBased) {
131155
$this->_dbuser = empty($dbuser) ? $this->_dbuser : $dbuser;
132156
$this->_dbpassword = empty($dbpassword) ? $this->_dbpassword : $dbpassword;
133-
$this->_options = $options;
157+
$this->_options = empty($options) ? $this->_options : $options;
134158

135159
// Must have a user and a password if not file based
136160
if ( empty($this->_dsn) || empty($this->_dbuser) || empty($this->_dbpassword) ) {
@@ -156,8 +180,7 @@ public function connect($dsn='', $dbuser='', $dbpassword='', $options=array(), $
156180
$this->dbh = new \PDO($this->_dsn, $this->_dbuser, $this->_dbpassword, $this->_options);
157181
$this->_connected = true;
158182
}
159-
}
160-
catch (\PDOException $e) {
183+
} catch (\PDOException $e) {
161184
$this->register_error($e->getMessage());
162185
$this->show_errors ? \trigger_error($e->getMessage() . '- $dsn: ' . $dsn, \E_USER_WARNING) : null;
163186
return false;
@@ -186,7 +209,8 @@ public function connect($dsn='', $dbuser='', $dbpassword='', $options=array(), $
186209
* Default is false
187210
* @return boolean
188211
*/
189-
public function quick_connect($dsn='', $user='', $password='', $options=array(), $isFileBased=false) {
212+
public function quick_connect($dsn = '', $user = '', $password = '', $options = array(), $isFileBased = false)
213+
{
190214
return $this->connect($dsn, $user, $password, $options, $isFileBased);
191215
} // quick_connect
192216

@@ -201,7 +225,8 @@ public function quick_connect($dsn='', $user='', $password='', $options=array(),
201225
* @param string $str
202226
* @return string
203227
*/
204-
public function escape($str) {
228+
public function escape($str)
229+
{
205230
// If there is no existing database connection then try to connect
206231
if ( ! isset($this->dbh) || ! $this->dbh ) {
207232
$this->connect($this->_dsn, $this->user, $this->password, $this->_options, $this->_isFileBased);
@@ -219,7 +244,8 @@ public function escape($str) {
219244
*
220245
* @return string
221246
*/
222-
public function sysdate() {
247+
public function sysdate()
248+
{
223249
return "datetime('now')";
224250
} // sysdate
225251

@@ -228,7 +254,8 @@ public function sysdate() {
228254
*
229255
* @return string
230256
*/
231-
public function catch_error(){
257+
public function catch_error()
258+
{
232259
$error_str = 'No error info';
233260

234261
$err_array = $this->dbh->errorInfo();
@@ -277,7 +304,9 @@ public function query_prepared($query, $param = null, $isselect = false)
277304
* @param type $query
278305
* @return object
279306
*/
280-
public function query($query, $use_prepare = false) {
307+
public function query($query, $use_prepare = false)
308+
{
309+
$param = [];
281310
if ($use_prepare)
282311
$param = $this->prepareValues();
283312

@@ -418,11 +447,20 @@ public function query($query, $use_prepare = false) {
418447
/**
419448
* Close the database connection
420449
*/
421-
public function disconnect(){
450+
public function disconnect()
451+
{
422452
if ($this->dbh) {
423453
$this->dbh = null;
424454
$this->_connected = false;
425455
}
426456
} // disconnect
427457

458+
/**
459+
* Get connection handle
460+
*/
461+
public function connection()
462+
{
463+
return $this->dbh;
464+
}
465+
428466
} // ezSQL_pdo

lib/ez_sql_postgresql.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
<?php
22

3-
/**********************************************************************
4-
* ezSQL Database specific class - PostgreSQL
5-
* Desc..: PostgreSQL component (part of ezSQL databse abstraction library)
6-
*
7-
* @author Justin Vincent ([email protected])
8-
* @author Stefanie Janine Stoelting <[email protected]>
9-
* Contributor: Lawrence Stubbs <[email protected]>
10-
* @link http://twitter.com/justinvincent
11-
* @name ezSQL_postgresql
12-
* @package ezSQL
13-
* @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
14-
*
15-
*/
16-
173
class ezSQL_postgresql extends ezSQLcore
184
{
195

@@ -74,8 +60,11 @@ class ezSQL_postgresql extends ezSQLcore
7460

7561
private $rows_affected = false;
7662

77-
protected $preparedvalues = array();
78-
63+
protected $preparedValues = array();
64+
65+
private static $isSecure = false;
66+
private static $secure = null;
67+
7968
/**
8069
* Constructor - allow the user to perform a quick connect at the same time
8170
* as initializing the ezSQL_postgresql class

lib/ez_sql_recordset.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
2-
/**
3-
* ezSQL Database specific class for working with query results
4-
* Desc..: recordset component (part of ezSQL databse abstraction library)
5-
*
6-
* @author Stefanie Janine Stoelting <[email protected]>
7-
* @name ezSQL_recordset
8-
* @package ezSQL
9-
* @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
10-
*
11-
*/
2+
123
class ezSQL_recordset implements \Iterator
134
{
145
/**

lib/ez_sql_sqlite3.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/**********************************************************************
4-
* Author: Justin Vincent ([email protected]) / Silvio Wanka
5-
* Contributor: Lawrence Stubbs <[email protected]>
6-
* Web...: http://twitter.com/justinvincent
7-
* Name..: ezSQL_sqlite3
8-
* Desc..: SQLite3 component (part of ezSQL databse abstraction library)
9-
*
10-
*/
11-
123
/**********************************************************************
134
* ezSQL error strings - SQLite
145
*/
@@ -32,7 +23,7 @@ class ezSQL_sqlite3 extends ezSQLcore
3223

3324
private $rows_affected = false;
3425

35-
protected $preparedvalues = array();
26+
protected $preparedValues = array();
3627

3728
/**********************************************************************
3829
* Constructor - allow the user to perform a quick connect at the

0 commit comments

Comments
 (0)