|
@@ -2,10 +2,19 @@
|
|
|
|
|
|
|
|
namespace ORM;
|
|
namespace ORM;
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Summary of DBInstance
|
|
|
|
|
+ */
|
|
|
class DBInstance
|
|
class DBInstance
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- private static function addPrefix($sql, $instance = 'default')
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Summary of addPrefix
|
|
|
|
|
+ * @param string $sql
|
|
|
|
|
+ * @param string $instance
|
|
|
|
|
+ * @return string
|
|
|
|
|
+ */
|
|
|
|
|
+ private static function addPrefix(string $sql, string $instance = 'default')
|
|
|
{
|
|
{
|
|
|
$con = Connections::getConnection($instance);
|
|
$con = Connections::getConnection($instance);
|
|
|
|
|
|
|
@@ -25,14 +34,11 @@ class DBInstance
|
|
|
*
|
|
*
|
|
|
* This method will execute a SQL on the database
|
|
* This method will execute a SQL on the database
|
|
|
*
|
|
*
|
|
|
- * @ctag DBInstance::execute($sql);
|
|
|
|
|
- * @ctag DBInstance::execute($sql, []);
|
|
|
|
|
- *
|
|
|
|
|
- * @param String $sql The SQL to be executed
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $sql The SQL to be executed
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*/
|
|
*/
|
|
|
- public static function execute($sql, $data = null, $instance = 'default')
|
|
|
|
|
|
|
+ public static function execute(string $sql, Array $data = null, string $instance = 'default')
|
|
|
{
|
|
{
|
|
|
$sql = self::addPrefix($sql, $instance);
|
|
$sql = self::addPrefix($sql, $instance);
|
|
|
if ($data) {
|
|
if ($data) {
|
|
@@ -43,12 +49,12 @@ class DBInstance
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- *
|
|
|
|
|
- * @ctag DBInstance::lastInsert();
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Summary of lastInsert
|
|
|
|
|
+ * @param string $instance
|
|
|
|
|
+ * @return mixed
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
- public static function lastInsert($instance = 'default')
|
|
|
|
|
|
|
+ public static function lastInsert(string $instance = 'default')
|
|
|
{
|
|
{
|
|
|
$con = Connections::getConnection($instance);
|
|
$con = Connections::getConnection($instance);
|
|
|
return $con->lastInsertId();
|
|
return $con->lastInsertId();
|
|
@@ -62,11 +68,11 @@ class DBInstance
|
|
|
* @ctag DBInstance::query($sql);
|
|
* @ctag DBInstance::query($sql);
|
|
|
* @ctag DBInstance::query($sql, []);
|
|
* @ctag DBInstance::query($sql, []);
|
|
|
*
|
|
*
|
|
|
- * @param String $sql The SQL to be executed
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $sql The SQL to be executed
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return pointer A pointer for a foreach loop
|
|
|
|
|
|
|
+ * @return mixed A pointer for a foreach loop
|
|
|
*/
|
|
*/
|
|
|
public static function query($sql, $data = null, $instance = 'default')
|
|
public static function query($sql, $data = null, $instance = 'default')
|
|
|
{
|
|
{
|
|
@@ -75,8 +81,12 @@ class DBInstance
|
|
|
if ($data) {
|
|
if ($data) {
|
|
|
return self::queryPrepare($sql, $data, $instance);
|
|
return self::queryPrepare($sql, $data, $instance);
|
|
|
} else {
|
|
} else {
|
|
|
- $con = Connections::getConnection($instance);
|
|
|
|
|
- return $con->query($sql, \PDO::FETCH_OBJ);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ $con = Connections::getConnection($instance);
|
|
|
|
|
+ return $con->query($sql, \PDO::FETCH_OBJ);
|
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
|
+ ddd($sql);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -88,13 +98,13 @@ class DBInstance
|
|
|
*
|
|
*
|
|
|
* This method will execute a SQL and return the first featched register
|
|
* This method will execute a SQL and return the first featched register
|
|
|
*
|
|
*
|
|
|
- * @param String $sql The SQL to be executed
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $sql The SQL to be executed
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return stdClass A object with the record info
|
|
|
|
|
|
|
+ * @return \stdClass A object with the record info
|
|
|
*/
|
|
*/
|
|
|
- public static function queryOne($sql, $data = null, $instance = 'default')
|
|
|
|
|
|
|
+ public static function queryOne(string $sql, Array $data = null, string $instance = 'default')
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
$sql = self::addPrefix($sql, $instance);
|
|
$sql = self::addPrefix($sql, $instance);
|
|
@@ -116,12 +126,12 @@ class DBInstance
|
|
|
* @ctag DBInstance::getRecord($table, []);
|
|
* @ctag DBInstance::getRecord($table, []);
|
|
|
* @ctag DBInstance::getRecord($table, [], []);
|
|
* @ctag DBInstance::getRecord($table, [], []);
|
|
|
*
|
|
*
|
|
|
- * @param String $table The table to be searched
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param Array $select Info to be put on the SELECT part of the query
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $table The table to be searched
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param array $select Info to be put on the SELECT part of the query
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return stdClass A object with the record info
|
|
|
|
|
|
|
+ * @return mixed A object with the record info
|
|
|
*/
|
|
*/
|
|
|
public static function getRecord($table, $data = array(), $select = array('*'), $instance = 'default')
|
|
public static function getRecord($table, $data = array(), $select = array('*'), $instance = 'default')
|
|
|
{
|
|
{
|
|
@@ -167,11 +177,11 @@ class DBInstance
|
|
|
* @ctag DBInstance::getRecordSql($sql);
|
|
* @ctag DBInstance::getRecordSql($sql);
|
|
|
* @ctag DBInstance::getRecordSql($sql, []);
|
|
* @ctag DBInstance::getRecordSql($sql, []);
|
|
|
*
|
|
*
|
|
|
- * @param String $sql The SQL to be executed
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $sql The SQL to be executed
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return stdClass A object with the record info
|
|
|
|
|
|
|
+ * @return mixed A object with the record info
|
|
|
*/
|
|
*/
|
|
|
public static function getRecordSql($sql, $data = null, $instance = 'default')
|
|
public static function getRecordSql($sql, $data = null, $instance = 'default')
|
|
|
{
|
|
{
|
|
@@ -193,12 +203,12 @@ class DBInstance
|
|
|
* @ctag DBInstance::getRecords($table);
|
|
* @ctag DBInstance::getRecords($table);
|
|
|
* @ctag DBInstance::getRecords($table, []);
|
|
* @ctag DBInstance::getRecords($table, []);
|
|
|
*
|
|
*
|
|
|
- * @param String $table The table to be searched
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param Array $select Info to be put on the SELECT part of the query
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $table The table to be searched
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param array $select Info to be put on the SELECT part of the query
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return stdClass A object with the record info
|
|
|
|
|
|
|
+ * @return array A object with the record info
|
|
|
*/
|
|
*/
|
|
|
public static function getRecords($table, $data = array(), $select = array('*'), $limits = array(), $instance = 'default')
|
|
public static function getRecords($table, $data = array(), $select = array('*'), $limits = array(), $instance = 'default')
|
|
|
{
|
|
{
|
|
@@ -220,12 +230,12 @@ class DBInstance
|
|
|
* @ctag DBInstance::getRecordsPointer($table);
|
|
* @ctag DBInstance::getRecordsPointer($table);
|
|
|
* @ctag DBInstance::getRecordsPointer($table, []);
|
|
* @ctag DBInstance::getRecordsPointer($table, []);
|
|
|
*
|
|
*
|
|
|
- * @param String $table The table to be searched
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param Array $select Info to be put on the SELECT part of the query
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $table The table to be searched
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param array $select Info to be put on the SELECT part of the query
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return stdClass A object with the record info
|
|
|
|
|
|
|
+ * @return mixed A object with the record info
|
|
|
*/
|
|
*/
|
|
|
public static function getRecordsPointer($table, $data = array(), $select = array('*'), $limits = array(), $instance = 'default')
|
|
public static function getRecordsPointer($table, $data = array(), $select = array('*'), $limits = array(), $instance = 'default')
|
|
|
{
|
|
{
|
|
@@ -277,11 +287,11 @@ class DBInstance
|
|
|
* @ctag DBInstance::getRecordsSql($sql);
|
|
* @ctag DBInstance::getRecordsSql($sql);
|
|
|
* @ctag DBInstance::getRecordsSql($sql, []);
|
|
* @ctag DBInstance::getRecordsSql($sql, []);
|
|
|
*
|
|
*
|
|
|
- * @param String $sql The SQL to be executed
|
|
|
|
|
- * @param Array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
- * @param String $instance Select the connection to execute
|
|
|
|
|
|
|
+ * @param string $sql The SQL to be executed
|
|
|
|
|
+ * @param array $data Pass the info to be replaced on the query_prepare
|
|
|
|
|
+ * @param string $instance Select the connection to execute
|
|
|
*
|
|
*
|
|
|
- * @return Array Array with objects representing the database data
|
|
|
|
|
|
|
+ * @return array Array with objects representing the database data
|
|
|
*/
|
|
*/
|
|
|
public static function getRecordsSql($sql, $data = null, $instance = 'default')
|
|
public static function getRecordsSql($sql, $data = null, $instance = 'default')
|
|
|
{
|
|
{
|
|
@@ -302,6 +312,13 @@ class DBInstance
|
|
|
return $elements;
|
|
return $elements;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Summary of insertRecord
|
|
|
|
|
+ * @param string $table
|
|
|
|
|
+ * @param array $data
|
|
|
|
|
+ * @param string $connection
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
public static function insertRecord($table, $data = array(), $connection = 'default')
|
|
public static function insertRecord($table, $data = array(), $connection = 'default')
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -330,12 +347,24 @@ class DBInstance
|
|
|
DBInstance::execute($sql, $insert_data, $connection);
|
|
DBInstance::execute($sql, $insert_data, $connection);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Summary of queryPrepare
|
|
|
|
|
+ * @param string $sql
|
|
|
|
|
+ * @param array $data
|
|
|
|
|
+ * @param string $instance
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ */
|
|
|
public static function queryPrepare($sql, $data = array(), $instance = 'default')
|
|
public static function queryPrepare($sql, $data = array(), $instance = 'default')
|
|
|
{
|
|
{
|
|
|
- $sql = self::addPrefix($sql, $instance);
|
|
|
|
|
- $con = Connections::getConnection($instance);
|
|
|
|
|
- $statement = $con->prepare($sql);
|
|
|
|
|
- $statement->execute($data);
|
|
|
|
|
- return $statement->fetchAll(\PDO::FETCH_OBJ);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ $sql = self::addPrefix($sql, $instance);
|
|
|
|
|
+ $con = Connections::getConnection($instance);
|
|
|
|
|
+ $statement = $con->prepare($sql);
|
|
|
|
|
+ $statement->execute($data);
|
|
|
|
|
+ return $statement->fetchAll(\PDO::FETCH_OBJ);
|
|
|
|
|
+ } catch (\Throwable $th) {
|
|
|
|
|
+ error_log('adsdsadsadsa');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|