|Classes of Malik Naik||PHP Ride Locale API||README.md||Download|
Locale API is an Application Programming Interface(API) which provides methods and classes to stores and retrieves the rides data from the Postgresql database and is written in PHP.
This is a Singleton class and provides the methods or functions to store and retrieve data from postgresql. The functions provided by this class are: * getInstance() - Returns the instance of this class. * getConnection() - Returns the database connection * createTable() - Creates the table in Postgresql database by passing the schema of the table as an argument along with table name. * insertRows() - Inserts multiple rows into the table and it takes two parameters one is the table name and other is the array of row arrays. * insertRow() - Inserts single row into the table * defaultSchema() - Adds default schema key/value pairs to the schema array. * isConnectionEstablished() - Returns if the connection is successfully established. * closeConnection() - Closes the connection
This class provides methods to read the .csv file and convert the data from the .csv file to array. The constructor of this class takes the file name of the .csv file to process.
The functions provided by this class are:
* isFileOpen() - Returns TRUE when the file pointer to the .csv file is set.
* toArray() - Reads the .csv file and generates an array containing the .csv file data and it has two optional parameters
This class provides methods necessary to fetch the required data from the database related to the rides. The constructor of this class takes the object of type
How to use this API?
To use the Locale API from other sources like web and mobile applications we need to generate the reponse as JSON format.
The following snippet retrieves all the rides from the table 'rides' with the columns/fields as id, user_id, travel_type_id, from_lat, and from_long and generates the response of the format JSON.
How to convert .csv file to array?
The CSVHandler class from the Locale namespace provides the method to convert the .csv file to array.
The following snippet shows how to convert .csv file to array:
NOTE: For more information on the parameters of the functions refer to the doc block at the top of the function in the class.