Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //connection from DB
- $db_connection = mysql_connect($host,$user,$pass);
- $db_select = mysql_select_db($db, $db_connect);
- //check or confirm query if there are errors
- function check_query($result_set){
- if(!$result_set){
- die("Failed to request query", mysql_error());
- }
- }
- //request data from db
- //if error put a $query argument
- function request_data($query){
- global $db_connect;
- $queried = mysql_query($query, $db_connection);
- check_query($queried);
- //return if query successful
- return $queried;
- }
- //get requested query
- //the purpose of the option is to choose what kind of fetching of data you want to use
- // usage = get_request_data("SELECT from blah blah", 1)
- function get_requested_data($query_set, $option){
- //get result from request data local $result as default
- //needs testing at home
- $result_set = request_data($query_set);
- /*
- /Notes:
- /need to make sure if $result_set has returned query if not I'm dead
- /choose how to get the data
- /$result_set should have a value to be placed on the fetching
- */
- if($option == 1){
- $row = mysql_fetch_array($result_set);
- return $row;
- }elseif($option == 2){
- $row = mysql_num_rows($result_set);
- return $row;
- }
- elseif($option == 3){
- $row = mysql_fetch_assoc($result_set);
- return $row;
- }
- elseif($option == 4){
- while($row == mysql_fetch_array($result_set)){
- //returns something 1 or many results
- return $row;
- }
- }
- else{
- //die("no result", mysql_error());
- return false;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment