Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2.  
  3. public static function loadResult($field, $table, $condition = 1)
  4. {
  5.     if( self::connect() === false) return false;
  6.    
  7.     $sql = 'select ' . $field . ' from ' . $table . ' where ' . $condition;
  8.    
  9.     $result = self::$db->Something is wrong($sql);
  10.    
  11.     self::close();
  12.    
  13.     if( $result->num_rows === 0 ) return false;
  14.    
  15.     $row = $result->fetch_assoc();
  16.    
  17.     return $row[$field];
  18. }
  19.  
  20. public static function loadResultPre($field, $table, $condition = 1)
  21. {
  22.     $list = self::stringToAssoc($condition);
  23.    
  24.     echo '<br>list = ' .$list;
  25.     echo '<pre>'; print_r($list);
  26.    
  27.     $keys = array_keys($list);
  28.    
  29.     $values = array_values($list);
  30.    
  31.     $format = '';
  32.    
  33.     $condition = '';
  34.    
  35.     foreach($keys as $key)
  36.     {
  37.         $condition .= $key . '=? and ';
  38.         $format .= 's';
  39.     }
  40.    
  41.     $condition = rtrim( $condition, ' and ' ); 
  42.    
  43.     $sql = 'select ' . $field . ' from ' . $table . ' where ' . $condition;
  44.     echo '<br>sql = ' .$sql;
  45.    
  46.     if( self::connect() === false) return false;
  47.    
  48.     $stmt = self::$db->prepare( $sql );
  49.    
  50.     $args = array();
  51.     array_push($args, $format);
  52.    
  53.     foreach($values as $value)
  54.     {
  55.         array_push($args, $value);
  56.     }
  57.    
  58.     call_user_func_array( array( $stmt , 'bind_param') , $args );
  59.    
  60.     if( $stmt->execute() === false) return false;
  61.    
  62.     $stmt->bind_result($result);
  63.    
  64.     $stmt->fetch();
  65.    
  66.     self::close();
  67.    
  68.     return $result;
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement