diff --git a/src/ORM/DBInstance.php b/src/ORM/DBInstance.php index 391ffe6..34f72bc 100755 --- a/src/ORM/DBInstance.php +++ b/src/ORM/DBInstance.php @@ -38,7 +38,7 @@ class DBInstance * @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(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); if ($data) { @@ -65,16 +65,13 @@ class DBInstance * * 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 array $data Pass the info to be replaced on the query_prepare * @param string $instance Select the connection to execute * * @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); @@ -85,7 +82,7 @@ class DBInstance $con = Connections::getConnection($instance); return $con->query($sql, \PDO::FETCH_OBJ); } catch (\Throwable $th) { - ddd($sql); + var_dump($th); die; } } } @@ -93,9 +90,6 @@ class DBInstance /** * queryOne * - * @ctag DBInstance::queryOne($sql); - * @ctag DBInstance::queryOne($sql, []); - * * This method will execute a SQL and return the first featched register * * @param string $sql The SQL to be executed @@ -122,10 +116,6 @@ class DBInstance * * 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 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 @@ -174,9 +164,6 @@ class DBInstance * * 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 array $data Pass the info to be replaced on the query_prepare * @param string $instance Select the connection to execute @@ -200,9 +187,6 @@ class DBInstance * * 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 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 @@ -212,6 +196,11 @@ class DBInstance */ 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); $elements = array(); @@ -227,9 +216,6 @@ class DBInstance * * 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 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 @@ -284,9 +270,6 @@ class DBInstance * * 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 array $data Pass the info to be replaced on the query_prepare * @param string $instance Select the connection to execute @@ -317,7 +300,8 @@ class DBInstance * @param string $table * @param array $data * @param string $connection - * @return void + * + * @return int */ public static function insertRecord($table, $data = array(), $connection = 'default') { @@ -345,6 +329,8 @@ class DBInstance $sql = "INSERT INTO {" . $table . "} ($first_argument) VALUES ($second_argument)"; DBInstance::execute($sql, $insert_data, $connection); + + return self::lastInsert($connection); } /** @@ -359,11 +345,16 @@ class DBInstance try { $sql = self::addPrefix($sql, $instance); $con = Connections::getConnection($instance); + + if($con->traceSQL){ + echo "$sql \n"; + } + $statement = $con->prepare($sql); $statement->execute($data); return $statement->fetchAll(\PDO::FETCH_OBJ); } catch (\Throwable $th) { - error_log('adsdsadsadsa'); + error_log($th); } }