Guest User

Untitled

a guest
Apr 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.39 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.  
  5. //connection from DB
  6.  
  7. $db_connection = mysql_connect($host,$user,$pass);
  8.  
  9. $db_select = mysql_select_db($db, $db_connect);
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. //check or confirm query if there are errors
  18.  
  19. function check_query($result_set){
  20.  
  21.  
  22.  
  23.    if(!$result_set){
  24.  
  25.                                 die("Failed to request query", mysql_error());
  26.  
  27.                 }
  28.  
  29.     }
  30.  
  31.  
  32.  
  33. //request data from db
  34.  
  35. //if error put a $query argument
  36.  
  37.  
  38.  
  39. function request_data($query){
  40.  
  41.                 global $db_connect;
  42.  
  43.                 $queried = mysql_query($query, $db_connection);
  44.  
  45.                 check_query($queried);
  46.  
  47.                 //return if query successful
  48.  
  49.         return $queried;
  50.  
  51. }
  52.  
  53. //get requested query
  54.  
  55. //the purpose of the option is to choose what kind of fetching of data you want to use
  56.  
  57. // usage = get_request_data("SELECT from blah blah", 1)
  58.  
  59.  
  60.  
  61. function get_requested_data($query_set, $option){
  62.  
  63.                
  64.  
  65.                 //get result from request data local $result as default
  66.  
  67.         //needs testing at home
  68.  
  69.                
  70.  
  71.                 $result_set = request_data($query_set);
  72.  
  73.                 /*
  74.  
  75.                 /Notes:
  76.  
  77.                 /need to make sure if $result_set has returned query if not I'm dead
  78.  
  79.                 /choose how to get the data
  80.  
  81.                 /$result_set should have a value to be placed on the fetching
  82.  
  83.                 */
  84.  
  85.                
  86.  
  87.                 if($option == 1){
  88.  
  89.                
  90.  
  91.                 $row = mysql_fetch_array($result_set);
  92.  
  93.                
  94.  
  95.                                 return $row;
  96.  
  97.                 }elseif($option == 2){
  98.  
  99.                 $row = mysql_num_rows($result_set);
  100.  
  101.                 return $row;
  102.  
  103.                 }
  104.  
  105.                   elseif($option == 3){
  106.  
  107.                   $row = mysql_fetch_assoc($result_set);
  108.  
  109.                   return $row;
  110.  
  111.                 }
  112.  
  113.                   elseif($option == 4){
  114.  
  115.  
  116.  
  117.                                 while($row == mysql_fetch_array($result_set)){
  118.  
  119.                                    //returns something 1 or many results
  120.  
  121.                                    return $row;
  122.  
  123.                                 }
  124.  
  125.                 }
  126.  
  127.                
  128.  
  129.                 else{
  130.  
  131.                      //die("no result", mysql_error());
  132.  
  133.                      return false;
  134.  
  135.                 }
  136.  
  137. }
  138.  
  139.  
  140.  
  141. ?>
Add Comment
Please, Sign In to add comment