Ticket #6836: insert.type.diff
File insert.type.diff, 1.1 KB (added by , 17 years ago) |
---|
-
wp-includes/wp-db.php
25 25 var $queries; 26 26 var $prefix = ''; 27 27 var $ready = false; 28 var $last_result; 28 29 29 30 // Our tables 30 31 var $posts; … … 330 331 * Insert an array of data into a table 331 332 * @param string $table WARNING: not sanitized! 332 333 * @param array $data should not already be SQL-escaped 334 * @param array $types should be key => sprintf style format specifier 333 335 * @return mixed results of $this->query() 334 336 */ 335 function insert($table, $data ) {337 function insert($table, $data, $types = array()) { 336 338 $data = add_magic_quotes($data); 337 339 $fields = array_keys($data); 340 $fields = add_magic_quotes($fields); 341 foreach( (array)$types as $key => $type ) { 342 if( ! isset($data[$key]) ) 343 continue; 344 $data[$key] = sprintf($type, $data[$key]); 345 } 346 338 347 return $this->query("INSERT INTO $table (`" . implode('`,`',$fields) . "`) VALUES ('".implode("','",$data)."')"); 339 348 } 340 349