Created
December 5, 2016 16:03
-
-
Save igoralves1/0244b01dbdee852dc700724aab1ec47c to your computer and use it in GitHub Desktop.
API class to grab info in the database using a sql query sent trough the URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //API | |
| public static function get_list($table,$displayType,$fields=NULL,$complement=NULL) {//Default = JSON | |
| try { | |
| $db=new db(); | |
| if(isset($fields) && isset($complement)){ | |
| $db->sql = "SELECT $fields FROM $table $complement;"; | |
| } | |
| else{ | |
| $db->sql = "SELECT * FROM $table;"; | |
| } | |
| //die($db->sql); | |
| $stmt = $db->conn->prepare($db->sql); | |
| $stmt->execute(); | |
| $result = $stmt->fetchAll(PDO::FETCH_NAMED); | |
| //die($displayType); | |
| if($displayType=="json"){ | |
| return json_encode($result); | |
| } | |
| else{ | |
| return print_r($result); | |
| } | |
| }// End of try | |
| catch(PDOException $e){ | |
| echo $e->getMessage(); | |
| $this->conn = null; | |
| die(); | |
| }// End of catch | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment