99use ezsql \Database ;
1010use ezsql \ezQueryInterface ;
1111use ezsql \DatabaseInterface ;
12+ use ezsql \Db ;
1213use ezsql \ezsqlModelInterface ;
1314
1415if (!\function_exists ('ezFunctions ' )) {
16+ /**
17+ * Returns the global database class, last created instance.
18+ *
19+ * @return ezQueryInterface|null
20+ */
21+ function getInstance (): ?ezQueryInterface
22+ {
23+ return Db::get ('global ' );
24+ }
25+
26+ /**
27+ * Clear/unset the global database class instance.
28+ */
29+ function clearInstance (): void
30+ {
31+ Db::clear ('global ' );
32+ }
33+
1534 /**
1635 * Initialize and connect a vendor's database.
1736 *
@@ -138,7 +157,7 @@ function sqliteInstance(array $databaseSetting = null, string $instanceTag = nul
138157 *
139158 * @return string|null `mysqli`|`pgsql`|`sqlite3`|`sqlsrv`
140159 */
141- function get_vendor (DatabaseInterface $ instance = null )
160+ function get_vendor (DatabaseInterface $ instance = null ): ? string
142161 {
143162 return ezSchema::vendor ($ instance );
144163 }
@@ -148,7 +167,7 @@ function get_vendor(DatabaseInterface $instance = null)
148167 *
149168 * @return string
150169 */
151- function to_string ($ arrays , $ separation = ', ' )
170+ function to_string ($ arrays , $ separation = ', ' ): string
152171 {
153172 return ezQuery::to_string ($ arrays , $ separation );
154173 }
@@ -479,38 +498,6 @@ function notBetween($x, $y, $y2, ...$args)
479498 return $ expression ;
480499 }
481500
482- /**
483- * Sets the global class instance for functions to call class methods directly.
484- *
485- * @param ezQueryInterface|null $ezSQL
486- *
487- * @return boolean - `true`, or `false` for error
488- */
489- function setInstance (ezQueryInterface $ ezSQL = null )
490- {
491- global $ ezInstance ;
492- $ status = false ;
493-
494- if ($ ezSQL instanceof ezQueryInterface) {
495- $ ezInstance = $ ezSQL ;
496- $ status = true ;
497- }
498-
499- return $ status ;
500- }
501-
502- /**
503- * Returns the global database class, last created instance or the one set with `setInstance()`.
504- *
505- * @return ezQueryInterface|null
506- */
507- function getInstance ()
508- {
509- global $ ezInstance ;
510-
511- return ($ ezInstance instanceof ezQueryInterface) ? $ ezInstance : null ;
512- }
513-
514501 /**
515502 * Get multiple row result set from the database (previously cached results).
516503 * Returns a multi dimensional array.
@@ -547,17 +534,6 @@ function get_results($output = \OBJECT, $instance = null)
547534 : false ;
548535 }
549536
550- /**
551- * Clear/unset the global database class instance.
552- */
553- function clearInstance ()
554- {
555- global $ ezInstance ;
556- $ GLOBALS ['ezInstance ' ] = null ;
557- $ ezInstance = null ;
558- unset($ GLOBALS ['ezInstance ' ]);
559- }
560-
561537 /**
562538 * Clean input string of XSS, html, javascript, etc...
563539 * @param string $string
0 commit comments