<?php
/*Servo Recipe*/
/*Recipe Name: MySQL data rendered as a HTML table*/
/*Recipe Description: This recipes connects to MySQL, using the 'sakila' demo database, and retrieves all the rows in the 'city' table. It then renders those rows as table.*/
/*Servo Recipe*/






/*s3rvo_functiondef_EWAGUJSPXN*/

/*Title: Get a GET Request value*/

/*Object: escapers_get_request_var_easy.json*/

/*Description: Gets a GET request value, with some helpful debugging*/

/*Tint: #2555FF*/

function aer_get_request_value($key) {

	if (isset($_GET[$key])) {

		return $_GET[$key];

	} else {

		echo "There is no GET request entry with the name '".$key."'.<br/>";

		if (count($_GET) == 0) {

			echo "The GET request appears to be entirely empty, are you sure you are calling this script with a GET request?<br/>";

		} else {

			echo "The contents of the GET request is as follows.<br/>";

			var_dump($_GET);

		}

	}

}

/*s3rvo_functiondef_EWAGUJSPXN*/





/*s3rvo_functioncall_BARAYBWFGT*/

/*Title: Get a GET Request value*/

/*Object: escapers_get_request_var_easy.json*/

/*Description: Gets a GET request value, with some helpful debugging*/

/*Tint: #2555FF*/

/*s3rvo_return_value*/$name = /*s3rvo_return_value*/servo_get_request_value(

/*s3rvo_param_$key*/"name"/*s3rvo_param_$key*/

);

/*s3rvo_functioncall_BARAYBWFGT*/





/*s3rvo_functiondef_POGYEJQNGE*/

/*Title: MySQL Connect*/

/*Object: escapers_mysql_connect.json*/

/*Description: Connect to a MySQL database, using the 'imysql' interface*/

/*Tint: #334466*/

function aer_mysql_connect($host,$username,$password,$database) {

	$con = mysqli_connect($host,$username,$password,$database);

	

	return $con;

	

}

                        

                    

/*s3rvo_functiondef_POGYEJQNGE*/







/*s3rvo_functioncall_IEBCXSZWCN*/

/*Title: MySQL Connect*/

/*Object: escapers_mysql_connect.json*/

/*Description: Connect to a MySQL database, using the 'imysql' interface*/

/*Tint: #334466*/

/*s3rvo_return_value*/$con = /*s3rvo_return_value*/servo_mysql_connect(

/*s3rvo_param_$host*/"localhost"/*s3rvo_param_$host*/,

/*s3rvo_param_$username*/"mike"/*s3rvo_param_$username*/,

/*s3rvo_param_$password*/"chunder12"/*s3rvo_param_$password*/,

/*s3rvo_param_$database*/"sakila"/*s3rvo_param_$database*/

);

/*s3rvo_functioncall_IEBCXSZWCN*/



/*s3rvo_functiondef_VVFJVMDSHS*/

/*Title: MySQL - Escape value*/

/*Object: escapers_escape_mysql_value.json*/

/*Description: Escapes (makes safe for use in MySQL) a value*/

/*Tint: #334466*/

function aer_mysql_escape_values($connection,$value) {

		return mysqli_real_escape_string($connection,$value);

}

/*s3rvo_functiondef_VVFJVMDSHS*/





/*s3rvo_functioncall_LEWKMUPYZT*/

/*Title: MySQL - Escape value*/

/*Object: escapers_escape_mysql_value.json*/

/*Description: Escapes (makes safe for use in MySQL) a value*/

/*Tint: #334466*/

/*s3rvo_return_value*/$name= /*s3rvo_return_value*/servo_mysql_escape_values(

/*s3rvo_param_$connection*/$con/*s3rvo_param_$connection*/,

/*s3rvo_param_$value*/$name/*s3rvo_param_$value*/

);

/*s3rvo_functioncall_LEWKMUPYZT*/









/*s3rvo_functiondef_LWPHPZPFBM*/

/*Title: MySQL Query*/

/*Object: escapers_mysql_query_and_return_results.json*/

/*Description: Runs a MySQL query, and returns the results*/

/*Tint: #334466*/

function aer_mysql_query($connection,$query) {

	

	$result = mysqli_query($connection,$query);



	$allrows = array();

	

	while($row = mysqli_fetch_assoc($result)) {

  		array_push($allrows, $row);

	}



	return $allrows;

}

/*s3rvo_functiondef_LWPHPZPFBM*/

/*s3rvo_functioncall_UIBFFQNVUD*/

/*Title: MySQL Query*/

/*Object: escapers_mysql_query_and_return_results.json*/

/*Description: Runs a MySQL query, and returns the results*/

/*Tint: #334466*/

/*s3rvo_return_value*/$result = /*s3rvo_return_value*/servo_mysql_query(

/*s3rvo_param_$connection*/$con/*s3rvo_param_$connection*/,

/*s3rvo_param_$query*/"SELECT * FROM city"/*s3rvo_param_$query*/

);

/*s3rvo_functioncall_UIBFFQNVUD*/

/*s3rvo_functiondef_NNKWYDLILI*/

/*Title: Output MySQL result set as an easy to read HTML table*/

/*Object: escapers_mysql_results_as_formatted_html_table.json*/

/*Description: Create a basically formatted HTML from a MySQL SELECT query result set.*/

/*Tint: #b65466*/

function aer_mysql_results_as_formatted_html_table($rows,$headerrow) {

	$table = "";

	$table .= "<table style=\"width:100%;border: 1px solid black;\">\n"; 

	

	if ($headerrow) {

		$table .= "\t<tr style=\"border: 1px solid black; background-color:grey\">\n";

		foreach ($rows[0] as $key => $value) {

		

    			$table .= "\t\t<td><b>$key</b></td>\n";

			

   		}

		$table .= "\t</tr>\n";

	}

	

	foreach ($rows as $row) {

   		$table .= "\t<tr>\n";

   		foreach ($row as $key => $value) {

			

    			$table .= "\t\t<td style=\"border-bottom: 1px solid black;  background-color:lightgrey\">$value</td>\n";

			

   		}

		$table .= "\t</tr>\n";

	}    

	$table .=  "</table>\n";

	return $table;

}

/*s3rvo_functiondef_NNKWYDLILI*/

/*s3rvo_functioncall_TOUIDGXZVV*/

/*Title: Output MySQL result set as an easy to read HTML table*/

/*Object: escapers_mysql_results_as_formatted_html_table.json*/

/*Description: Create a basically formatted HTML from a MySQL SELECT query result set.*/

/*Tint: #b65466*/

/*s3rvo_return_value*/echo/*s3rvo_return_value*/servo_mysql_results_as_formatted_html_table(

/*s3rvo_param_$resultset*/$result/*s3rvo_param_$resultset*/,

/*s3rvo_param_$headerrow*/true/*s3rvo_param_$headerrow*/

);

/*s3rvo_functioncall_TOUIDGXZVV*/























































































































































































?>