Some identation and minor changes

This commit is contained in:
2026-08-19 10:57:31 -03:00
parent bd2f3bddff
commit ac04cd02f4
+18 -27
View File
@@ -38,7 +38,7 @@ class DBInstance
* @param array $data Pass the info to be replaced on the query_prepare * @param array $data Pass the info to be replaced on the query_prepare
* @param string $instance Select the connection to execute * @param string $instance Select the connection to execute
*/ */
public static function execute(string $sql, Array $data = null, string $instance = 'default') public static function execute(string $sql, Array $data = Array(), string $instance = 'default')
{ {
$sql = self::addPrefix($sql, $instance); $sql = self::addPrefix($sql, $instance);
if ($data) { if ($data) {
@@ -65,16 +65,13 @@ class DBInstance
* *
* This method will execute a SQL and return a pointer to the resultset * This method will execute a SQL and return a pointer to the resultset
* *
* @ctag DBInstance::query($sql);
* @ctag DBInstance::query($sql, []);
*
* @param string $sql The SQL to be executed * @param string $sql The SQL to be executed
* @param array $data Pass the info to be replaced on the query_prepare * @param array $data Pass the info to be replaced on the query_prepare
* @param string $instance Select the connection to execute * @param string $instance Select the connection to execute
* *
* @return mixed 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(string $sql, array $data = [], $instance = 'default')
{ {
$sql = self::addPrefix($sql, $instance); $sql = self::addPrefix($sql, $instance);
@@ -85,7 +82,7 @@ class DBInstance
$con = Connections::getConnection($instance); $con = Connections::getConnection($instance);
return $con->query($sql, \PDO::FETCH_OBJ); return $con->query($sql, \PDO::FETCH_OBJ);
} catch (\Throwable $th) { } catch (\Throwable $th) {
ddd($sql); var_dump($th); die;
} }
} }
} }
@@ -93,9 +90,6 @@ class DBInstance
/** /**
* queryOne * queryOne
* *
* @ctag DBInstance::queryOne($sql);
* @ctag DBInstance::queryOne($sql, []);
*
* 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 string $sql The SQL to be executed
@@ -122,10 +116,6 @@ class DBInstance
* *
* This method will execute get a register from a table * This method will execute get a register from a table
* *
* @ctag DBInstance::getRecord($table);
* @ctag DBInstance::getRecord($table, []);
* @ctag DBInstance::getRecord($table, [], []);
*
* @param string $table The table to be searched * @param string $table The table to be searched
* @param array $data Pass the info to be replaced on the query_prepare * @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 array $select Info to be put on the SELECT part of the query
@@ -174,9 +164,6 @@ class DBInstance
* *
* This method will get a record from the database using SQL * This method will get a record from the database using SQL
* *
* @ctag DBInstance::getRecordSql($sql);
* @ctag DBInstance::getRecordSql($sql, []);
*
* @param string $sql The SQL to be executed * @param string $sql The SQL to be executed
* @param array $data Pass the info to be replaced on the query_prepare * @param array $data Pass the info to be replaced on the query_prepare
* @param string $instance Select the connection to execute * @param string $instance Select the connection to execute
@@ -200,9 +187,6 @@ class DBInstance
* *
* This method will get records from the database * This method will get records from the database
* *
* @ctag DBInstance::getRecords($table);
* @ctag DBInstance::getRecords($table, []);
*
* @param string $table The table to be searched * @param string $table The table to be searched
* @param array $data Pass the info to be replaced on the query_prepare * @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 array $select Info to be put on the SELECT part of the query
@@ -212,6 +196,11 @@ class DBInstance
*/ */
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')
{ {
if(empty($data)){
$data = array("1" => ['=', 1]);
}
$pointer = self::getRecordsPointer($table, $data, $select, $limits, $instance); $pointer = self::getRecordsPointer($table, $data, $select, $limits, $instance);
$elements = array(); $elements = array();
@@ -227,9 +216,6 @@ class DBInstance
* *
* This method will get records from the database * This method will get records from the database
* *
* @ctag DBInstance::getRecordsPointer($table);
* @ctag DBInstance::getRecordsPointer($table, []);
*
* @param string $table The table to be searched * @param string $table The table to be searched
* @param array $data Pass the info to be replaced on the query_prepare * @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 array $select Info to be put on the SELECT part of the query
@@ -284,9 +270,6 @@ class DBInstance
* *
* This method will get records from the database * This method will get records from the database
* *
* @ctag DBInstance::getRecordsSql($sql);
* @ctag DBInstance::getRecordsSql($sql, []);
*
* @param string $sql The SQL to be executed * @param string $sql The SQL to be executed
* @param array $data Pass the info to be replaced on the query_prepare * @param array $data Pass the info to be replaced on the query_prepare
* @param string $instance Select the connection to execute * @param string $instance Select the connection to execute
@@ -317,7 +300,8 @@ class DBInstance
* @param string $table * @param string $table
* @param array $data * @param array $data
* @param string $connection * @param string $connection
* @return void *
* @return int
*/ */
public static function insertRecord($table, $data = array(), $connection = 'default') public static function insertRecord($table, $data = array(), $connection = 'default')
{ {
@@ -345,6 +329,8 @@ class DBInstance
$sql = "INSERT INTO {" . $table . "} ($first_argument) VALUES ($second_argument)"; $sql = "INSERT INTO {" . $table . "} ($first_argument) VALUES ($second_argument)";
DBInstance::execute($sql, $insert_data, $connection); DBInstance::execute($sql, $insert_data, $connection);
return self::lastInsert($connection);
} }
/** /**
@@ -359,11 +345,16 @@ class DBInstance
try { try {
$sql = self::addPrefix($sql, $instance); $sql = self::addPrefix($sql, $instance);
$con = Connections::getConnection($instance); $con = Connections::getConnection($instance);
if($con->traceSQL){
echo "$sql \n";
}
$statement = $con->prepare($sql); $statement = $con->prepare($sql);
$statement->execute($data); $statement->execute($data);
return $statement->fetchAll(\PDO::FETCH_OBJ); return $statement->fetchAll(\PDO::FETCH_OBJ);
} catch (\Throwable $th) { } catch (\Throwable $th) {
error_log('adsdsadsadsa'); error_log($th);
} }
} }