Помощник
|
Фрагмент кода - добавления контента в БД, Помогите найти в wordpress (лень) |
FordogeN
|
Сообщение
#1
|
||
|
|
||
|
|||
ZiTosS |
2.6.2011, 12:24;
Ответить: ZiTosS
Сообщение
#2
|
|
|
FordogeN, хм, не думаю что кому-то захочется сидеть и формировать структуру БД
wp-includes/comment.php - Добавление в базу комментария: строка 1226 [php] $wpdb->insert($wpdb->comments, $data);[/php] wp-includes/post.php - Добавление в базу поста: строка 2567 [php] if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {[/php] wp-includes/post.php - Добавление в базу вложения к посту: строка 3645 [php] $wpdb->insert( $wpdb->posts, $data );[/php] wp-includes/user.php - Добавление в базу пользователя: строка 1486 [php] $wpdb->insert( $wpdb->users, $data + compact( 'user_login' ) );[/php] А вот и метод вставки данных в БД и метод-helper (wp-includes/wp-db.php) [php] /** * Insert a row into a table. * * <code> * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) ) * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) ) * </code> * * @since 2.5.0 * @see wpdb::prepare() * @see wpdb::$field_types * @see wp_set_wpdb_vars() * * @param string $table table name * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). * @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. * 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. * @return int|false The number of rows inserted, or false on error. */ function insert( $table, $data, $format = null ) { return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' ); } /* .... */ /** * Helper function for insert and replace. * * Runs an insert or replace query based on $type argument. * * @access private * @since 3.0.0 * @see wpdb::prepare() * @see wpdb::$field_types * @see wp_set_wpdb_vars() * * @param string $table table name * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped). * @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. * 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. * @return int|false The number of rows affected, or false on error. */ function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) { if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) ) return false; $formats = $format = (array) $format; $fields = array_keys( $data ); $formatted_fields = array(); foreach ( $fields as $field ) { if ( !empty( $format ) ) $form = ( $form = array_shift( $formats ) ) ? $form : $format[0]; elseif ( isset( $this->field_types[$field] ) ) $form = $this->field_types[$field]; else $form = '%s'; $formatted_fields[] = $form; } $sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')"; return $this->query( $this->prepare( $sql, $data ) ); }[/php]
|
|
|
||
|
Похожие темы
Тема | Ответов | Автор | Просмотров | Последний ответ | |
---|---|---|---|---|---|
A-Parser 1.1 - продвинутый парсер ПС, кейвордов, контента, показателей, 70+ парсеров. | 353 | Forbidden | 279269 | 11.4.2024, 17:07 автор: AParser_Support |
|
Сайт не индексируется в Google без добавления ссылок в адурилку | 4 | Nekit | 1083 | 20.3.2024, 21:44 автор: MorKer |
|
Дайте бесплатного контента! :) | 2 | Tia2 | 999 | 22.12.2023, 18:53 автор: zyzy |
|
Занимаюсь добычей качественного контента из Вебархива. Опыт уже более трех лет Предоставляю только качественный, читабельный контент. |
62 | kuz999 | 38094 | 27.7.2023, 13:55 автор: kuz999 |
|
Ищу помощника (SEO, сбор информации, размещение контента на сайтах, рутина) | 0 | rokot | 830 | 8.2.2023, 18:35 автор: rokot |
Текстовая версия | Сейчас: 19.4.2024, 13:04 |