Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * from a query string, prepare a mysqli statement and execute it
- * @param $query_str
- * @param $fields array of fields that will be bound to the query
- * @return the query results
- */
- private function build_and_execute( $query_str, $fields ) {
- $dbc = \appcore\config::database( $this->_database );
- $mysqli = new \mysqli( $dbc['host'], $dbc['login'], $dbc['password'], $dbc['db_name'] );
- $statement = $mysqli->prepare( $query_str );
- # build the param 1 of bind_param(), the definition string
- $bind_types = array();
- foreach ( $fields as $field ) $bind_types[] = $this->_field_types[ $field ];
- $bind_string = implode( '', $bind_types );
- # build the array of references
- $field_values = array();
- $bind_params = array();
- foreach ( $fields as $i => $v ) {
- $bind_var = 'bind_field_' . $i;
- $$bind_var = $this->_fields[ $v ];
- $bind_params[$i] = &$$bind_var;
- }
- array_unshift( $bind_params, $bind_string );
- call_user_func_array( array( $statement, 'bind_param' ), $bind_params );
- return $statement->execute();
- }
Add Comment
Please, Sign In to add comment