progetto201 API
|
COLORS: manages the colors table. More...
Functions | |
get_colors ($t_conn_res) | |
Returns the colors data inside an associative array (the key is called 'data'). More... | |
Variables | |
$response = array('errors' => array()) | |
Default response array. More... | |
COLORS: manages the colors table.
Client perspective:
This script sets the content type to "JSON", includes the db_connection.php script
Which is used to connect to MySQL and to execute simple select queries (no prepared statements)
and then it defines the response array.
A function is defined:
get_colors($t_conn_res)
Returns colors data inside an associative array. The name of its key is 'data'.
If the script is not included in other scripts, the script tries to connect to the database, and checks the request method:
When the function finishes, the script closes the connection to the DB, and the data (or errors) is collected in the "response" array. The response array is then returned to the client in JSON format
List of possible errors:
Check if n is numeric and positive (now returns all the colors if n<0)
Check if min and max are numeric and min < max (currently returns "Query Returned nothing" in these cases))
get_colors | ( | $t_conn_res | ) |
Returns the colors data inside an associative array (the key is called 'data').
The function, using the mysqli object inside the $t_conn_res parameter ($t_conn_res['connect_obj']), executes the '$query' query that collects the colors requested by the client.
The returned data depends on which parameters were passed with the request:
The data of the each color is contained inside an associative array:
the format of color_hex is:
#RRGGBB
If the query execution throws an error, the error is collected in the array with the 'errors' key. The errors have 3 properties:
the error message is written in english
If there are errors, they are collected in the returned array. The function can retun the following errors:
array | $t_conn_res | array with the connection object (connection is successfull) |
$response = array('errors' => array()) |
Default response array.