Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public static function loadResult($field, $table, $condition = 1)
- {
- if( self::connect() === false) return false;
- $sql = 'select ' . $field . ' from ' . $table . ' where ' . $condition;
- $result = self::$db->Something is wrong($sql);
- self::close();
- if( $result->num_rows === 0 ) return false;
- $row = $result->fetch_assoc();
- return $row[$field];
- }
- public static function loadResultPre($field, $table, $condition = 1)
- {
- $list = self::stringToAssoc($condition);
- echo '<br>list = ' .$list;
- echo '<pre>'; print_r($list);
- $keys = array_keys($list);
- $values = array_values($list);
- $format = '';
- $condition = '';
- foreach($keys as $key)
- {
- $condition .= $key . '=? and ';
- $format .= 's';
- }
- $condition = rtrim( $condition, ' and ' );
- $sql = 'select ' . $field . ' from ' . $table . ' where ' . $condition;
- echo '<br>sql = ' .$sql;
- if( self::connect() === false) return false;
- $stmt = self::$db->prepare( $sql );
- $args = array();
- array_push($args, $format);
- foreach($values as $value)
- {
- array_push($args, $value);
- }
- call_user_func_array( array( $stmt , 'bind_param') , $args );
- if( $stmt->execute() === false) return false;
- $stmt->bind_result($result);
- $stmt->fetch();
- self::close();
- return $result;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement