소스 검색

Update database.php

FusionPBX 6 년 전
부모
커밋
32a45b9f36
1개의 변경된 파일26개의 추가작업 그리고 8개의 파일을 삭제
  1. 26 8
      resources/classes/database.php

+ 26 - 8
resources/classes/database.php

@@ -450,7 +450,7 @@ include "root.php";
 			}
 
 			// Use this function to execute complex queries
-			public function execute($sql, $parameters = null) {
+			public function execute($sql, $parameters = null, $return_type = 'all') {
 
 				//connect to the database if needed
 					if (!$this->db) {
@@ -476,9 +476,18 @@ include "root.php";
 							$message["parameters"] = $parameters;
 						}
 						$this->message = $message;
-						//$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
-						//unset($prep_statement);
-						return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+
+						//return the results
+						switch($return_type) {
+						case 'all':
+							return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+						case 'row':
+							return $prep_statement->fetch(PDO::FETCH_ASSOC);
+						case 'column';
+							return $prep_statement->fetchColumn();
+						default:
+							return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+						}
 					}
 					catch(PDOException $e) {
 						$message["message"] = "Bad Request";
@@ -906,7 +915,7 @@ include "root.php";
 
 			} //count
 
-			public function select($sql, $parameters = null) {
+			public function select($sql, $parameters = '', $return_type = 'all') {
 
 				//connect to the database if needed
 					if (!$this->db) {
@@ -932,9 +941,18 @@ include "root.php";
 							$message["parameters"] = $parameters;
 						}
 						$this->message = $message;
-						//$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
-						//unset($prep_statement);
-						return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+
+						//return the results
+						switch($return_type) {
+						case 'all':
+							return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+						case 'row':
+							return $prep_statement->fetch(PDO::FETCH_ASSOC);
+						case 'column';
+							return $prep_statement->fetchColumn();
+						default:
+							return $prep_statement->fetchAll(PDO::FETCH_ASSOC);
+						}
 					}
 					catch(PDOException $e) {
 						$message["message"] = "Bad Request";