Changeset 13454
- Timestamp:
- 02/27/2010 03:45:09 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/wp-db.php
r13426 r13454 1144 1144 * 1145 1145 * @param string $table table name 1146 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1147 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. 1148 * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1149 * @return int|false The number of rows inserted, or false on error. 1150 */ 1151 function insert( $table, $data, $format = null ) { 1152 return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); 1153 } 1154 1155 /** 1156 * Replace a row into a table. 1157 * 1158 * <code> 1159 * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) 1160 * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) 1161 * </code> 1162 * 1163 * @since 3.0.0 1164 * @see wpdb::prepare() 1165 * @see wpdb::$field_types 1166 * @see wp_set_wpdb_vars() 1167 * 1168 * @param string $table table name 1169 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1170 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. 1171 * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1172 * @return int|false The number of rows affected, or false on error. 1173 */ 1174 function replace( $table, $data, $format = null ) { 1175 return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' ); 1176 } 1177 1178 /** 1179 * Helper function for insert and replace. 1180 * 1181 * Runs an insert or replace query based on $type argument. 1182 * 1183 * @access private 1184 * @since 3.0.0 1185 * @see wpdb::prepare() 1186 * @see wpdb::$field_types 1187 * @see wp_set_wpdb_vars() 1188 * 1189 * @param string $table table name 1146 1190 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). 1147 1191 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data. 1148 1192 * A format is one of '%d', '%s' (decimal number, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types. 1149 * @return int|false The number of rows inserted, or false on error. 1150 */ 1151 function insert( $table, $data, $format = null ) { 1193 * @return int|false The number of rows affected, or false on error. 1194 */ 1195 function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { 1196 if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) 1197 return false; 1152 1198 $formats = $format = (array) $format; 1153 1199 $fields = array_keys( $data ); … … 1162 1208 $formatted_fields[] = $form; 1163 1209 } 1164 $sql = " INSERTINTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";1210 $sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')"; 1165 1211 return $this->query( $this->prepare( $sql, $data ) ); 1166 1212 } 1167 1168 1213 1169 1214 /**
Note: See TracChangeset
for help on using the changeset viewer.