Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //A script to execute sql queries
- //I'll prefer if result can be sent as XML
- //But you can just echo them if it's not possible
- //NB: error messages should be prefixed with ERROR:
- $uname = filter_input(INPUT_GET, 'u');
- $pwd = filter_input(INPUT_GET, 'p');
- $type = filter_input(INPUT_GET, 'sql_type');
- $query = filter_input(INPUT_GET, 'q');
- $con = mysql_connect('localhost', $uname, $pwd);
- if ($con) {
- mysql_select_db('csfonlin_db1');
- if (strcasecmp($type, 'select') == 0) {
- //For MySql select statements
- //Steps:
- //Execute statement
- //if successful, send result
- //Else send error message
- } elseif (strcasecmp($type, 'batch') == 0) {
- //For a MySql transaction (i.e a group of statements)
- //These group of statements are seperated by ';'
- $querys = explode(';', $query);
- //Steps:
- //In a loop, execute each statement
- //if error occurs, send an error messages indicating the index of the query at which the error occurred
- //If all successful, send an ok message
- } elseif (strcasecmp($type, 'update') == 0) {
- //For other MySql statements (This is for statements that do not return data)
- //Steps:
- //Execute statement
- //Send an ok message if successful
- //else, send an error message
- } else {
- //Send an error message
- //e.g
- echo error_message('Unknown sql type');
- }
- } else {
- //Send an error message
- //e.g
- echo error_message('Unable to connect to database');
- }
- mysql_close($con);
- function error_message(string $message) {
- return 'ERROR: ' . err_msg;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement