当前位置: 首页>>代码示例>>PHP>>正文


PHP wpdb::query方法代码示例

本文整理汇总了PHP中wpdb::query方法的典型用法代码示例。如果您正苦于以下问题:PHP wpdb::query方法的具体用法?PHP wpdb::query怎么用?PHP wpdb::query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wpdb的用法示例。


在下文中一共展示了wpdb::query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: launchkey_cron

 public function launchkey_cron()
 {
     $table_name = $this->wpdb->prefix . 'launchkey_sso_sessions';
     $dt = new DateTime("- 1 hour");
     $dt->setTimezone(new DateTimeZone("UTC"));
     $this->wpdb->query($this->wpdb->prepare("DELETE FROM {$table_name} WHERE seen < %s", $dt->format("Y-m-d H:i:s")));
 }
开发者ID:aenglander,项目名称:launchkey-wordpress,代码行数:7,代码来源:class-launchkey-wp-bootstrap.php

示例2: remove_db_tables

 public function remove_db_tables()
 {
     $table = $this->wpdb->prefix . 'icl_string_pages';
     $this->wpdb->query('DROP TABLE IF EXISTS ' . $table);
     $table = $this->wpdb->prefix . 'icl_string_urls';
     $this->wpdb->query('DROP TABLE IF EXISTS ' . $table);
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:7,代码来源:class-wpml-st-reset.php

示例3: query

 /**
  * {@inheritdoc}
  */
 public function query($sql)
 {
     $sql = $this->_prepareSql($sql);
     $result = $this->_db->query($sql);
     $this->_checkError();
     return $result;
 }
开发者ID:JBZoo,项目名称:CrossCMS,代码行数:10,代码来源:Database.php

示例4: query

 public function query($query, $parameters = array())
 {
     if (!empty($parameters)) {
         $query = str_replace('?', '%s', $query);
         $query = $this->wpdb->prepare($query, $parameters);
     }
     return $this->wpdb->query($query);
 }
开发者ID:nayabbukhari,项目名称:circulocristiano,代码行数:8,代码来源:WpDatabase.php

示例5: reassign_terms

 /**
  * Performs an SQL query assigning all terms to their correct language equivalent if it exists.
  * This should only be run after the previous functionality in here has finished.
  * Afterwards the term counts are recalculated globally, since term assignments bypassing the WordPress Core,
  * will not trigger any sort of update on those.
  */
 private function reassign_terms()
 {
     $update_query = $this->wpdb->prepare("UPDATE {$this->wpdb->term_relationships} AS o,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ic,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS iw,\n\t\t\t\t\t{$this->wpdb->prefix}icl_translations AS ip,\n\t\t\t\t\t{$this->wpdb->posts} AS p\n\t\t\t\t\t\tSET o.term_taxonomy_id = ic.element_id\n\t\t\t\t\t\tWHERE ic.trid = iw.trid\n\t\t\t\t\t\t\tAND ic.element_type = iw.element_type\n\t\t\t\t\t\t\tAND iw.element_id = o.term_taxonomy_id\n\t\t\t\t\t\t\tAND ic.language_code = ip.language_code\n\t\t\t\t\t\t\tAND ip.element_type = CONCAT('post_', p.post_type)\n\t\t\t\t\t\t\tAND ip.element_id = p.ID\n\t\t\t\t\t\t\tAND o.object_id = p.ID\n\t\t\t\t\t\t\tAND o.term_taxonomy_id != ic.element_id\n\t\t\t\t\t\t\tAND iw.element_type = %s", 'tax_' . $this->taxonomy);
     $rows_affected = $this->wpdb->query($update_query);
     if ($rows_affected) {
         $term_ids = $this->wpdb->get_col($this->wpdb->prepare("SELECT term_taxonomy_id FROM {$this->wpdb->term_taxonomy} WHERE taxonomy = %s", $this->taxonomy));
         // Do not run the count update on taxonomies that are not actually registered as proper taxonomy objects, e.g. WooCommerce Product Attributes.
         $taxonomy_object = $this->sitepress->get_wp_api()->get_taxonomy($this->taxonomy);
         if ($taxonomy_object && isset($taxonomy_object->object_type)) {
             $this->sitepress->get_wp_api()->wp_update_term_count($term_ids, $this->taxonomy);
         }
     }
 }
开发者ID:aarongillett,项目名称:B22-151217,代码行数:19,代码来源:wpml-term-language-synchronization.class.php

示例6: tearDown

 public function tearDown()
 {
     // Remove test tables.
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 0');
     $this->wpdb->query('DROP TABLE `test_types`');
     $this->wpdb->query('DROP TABLE `test_table`');
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 1');
     // Uninstall
     if (!defined('WP_UNINSTALL_PLUGIN')) {
         define('WP_UNINSTALL_PLUGIN', 'tabulate/tabulate.php');
     }
     require __DIR__ . '/../uninstall.php';
     parent::tearDown();
 }
开发者ID:kcdipesh,项目名称:tabulate,代码行数:14,代码来源:TestBase.php

示例7: persist

 private function persist()
 {
     foreach (array_chunk($this->data, self::INSERT_CHUNK_SIZE) as $chunk) {
         $query = "INSERT IGNORE INTO {$this->wpdb->prefix}icl_strings " . '(`language`, `context`, `gettext_context`, `domain_name_context_md5`, `name`, `value`, `status`) VALUES ';
         $i = 0;
         foreach ($chunk as $string) {
             if ($i > 0) {
                 $query .= ',';
             }
             $query .= $this->wpdb->prepare("('%s', '%s', '%s', '%s', '%s', '%s', %d)", $this->get_source_lang($string['name'], $string['domain']), $string['domain'], $string['gettext_context'], md5($string['domain'] . $string['name'] . $string['gettext_context']), $string['name'], $string['value'], ICL_TM_NOT_TRANSLATED);
             $i++;
         }
         $this->wpdb->query($query);
     }
 }
开发者ID:studiopengpeng,项目名称:ASCOMETAL,代码行数:15,代码来源:class-wpml-autoregister-save-strings.php

示例8: query

 /**
  * Perform a MySQL database query, using current database connection.
  *
  * @see wpdb::query()
  *
  * @param string $query Database query
  * @return int|false Number of rows affected/selected or false on error
  */
 function query($query)
 {
     if (!$this->ready) {
         if (isset($this->check_current_query)) {
             // This property was introduced in WP 4.2
             $this->check_current_query = true;
         }
         return false;
     }
     if ($this->show_errors) {
         $this->hide_errors();
     }
     $result = parent::query($query);
     if (!SAVEQUERIES) {
         return $result;
     }
     $i = $this->num_queries - 1;
     $this->queries[$i]['trace'] = new QM_Backtrace(array('ignore_items' => 1));
     if ($this->last_error) {
         $this->queries[$i]['result'] = new WP_Error('qmdb', $this->last_error);
     } else {
         $this->queries[$i]['result'] = $result;
     }
     return $result;
 }
开发者ID:darbymanning,项目名称:Family-Church,代码行数:33,代码来源:db.php

示例9: saveLicense

 /**
  * Update or insert a license.
  *
  * @param Wslm_ProductLicense|array $license
  * @return Wslm_ProductLicense
  */
 public function saveLicense($license)
 {
     if (is_array($license)) {
         $license = new Wslm_ProductLicense($license);
     }
     $data = $license->getData();
     //The license object might have some virtual or computed fields that don't exist in the DB.
     //If we try to update/insert those, we'll get an SQL error. So lets filter the data array
     //to ensure only valid fields are included in the query.
     $licenseDbFields = array('license_id', 'license_key', 'product_id', 'product_slug', 'customer_id', 'status', 'issued_on', 'expires_on', 'max_sites');
     $licenseDbFields = apply_filters('wslm_license_db_fields', $licenseDbFields);
     $data = array_intersect_key($data, array_flip($licenseDbFields));
     if (is_numeric($data['expires_on'])) {
         $data['expires_on'] = date('Y-m-d H:i:s', $data['expires_on']);
     }
     if ($license->get('license_id') === null) {
         //wpdb converts null values to "0" which is not what we want.
         //When inserting, we can simply strip them and let the DB fill in the blanks with NULLs.
         $data = array_filter($data, __CLASS__ . '::isNotNull');
         $this->wpdb->insert($this->tablePrefix . 'licenses', $data);
         $license['license_id'] = $this->wpdb->insert_id;
     } else {
         //When updating, we need to check for nulls and treat them differently,
         //so we can't use $wpdb->update here.
         $query = "UPDATE {$this->tablePrefix}licenses SET ";
         $expressions = array();
         foreach ($data as $field => $value) {
             $expressions[] = $field . ' = ' . ($value === null ? 'NULL' : $this->wpdb->prepare('%s', $value));
         }
         $query .= implode(', ', $expressions);
         $query .= ' WHERE license_id = ' . absint($license['license_id']);
         $this->wpdb->query($query);
     }
     return $license;
 }
开发者ID:rafabrutaldrums,项目名称:siclo,代码行数:41,代码来源:LicenseServer.php

示例10: tearDown

 public function tearDown()
 {
     // Remove test tables.
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 0');
     $this->wpdb->query('DROP TABLE IF EXISTS `test_types`');
     $this->wpdb->query('DROP TABLE IF EXISTS `test_table`');
     $this->wpdb->query('SET FOREIGN_KEY_CHECKS = 1');
     $ct = new \WordPress\Tabulate\DB\ChangeTracker($this->wpdb);
     $ct->close_changeset();
     // Uninstall
     if (!defined('WP_UNINSTALL_PLUGIN')) {
         define('WP_UNINSTALL_PLUGIN', 'tabulate/tabulate.php');
     }
     require __DIR__ . '/../uninstall.php';
     parent::tearDown();
 }
开发者ID:gitter-badger,项目名称:tabulate-1,代码行数:16,代码来源:TestBase.php

示例11: save

 /**
  * Save entity to database.
  *
  * @return int|false
  */
 public function save()
 {
     // Prepare query data.
     $set = array();
     $values = array();
     foreach ($this->values as $field => $value) {
         if ($field == 'id') {
             continue;
         }
         if ($value === null) {
             $set[] = sprintf('`%s` = NULL', $field);
         } else {
             $set[] = sprintf('`%s` = %s', $field, $this->formats[$field]);
             $values[] = $value;
         }
     }
     // Run query.
     if ($this->values['id']) {
         $res = $this->wpdb->query($this->wpdb->prepare(sprintf('UPDATE `%s` SET %s WHERE `id` = %d', $this->table_name, implode(', ', $set), $this->values['id']), $values));
     } else {
         $res = $this->wpdb->query($this->wpdb->prepare(sprintf('INSERT INTO `%s` SET %s', $this->table_name, implode(', ', $set)), $values));
         if ($res) {
             $this->values['id'] = $this->wpdb->insert_id;
         }
     }
     return $res;
 }
开发者ID:VLabsInc,项目名称:WordPressPlatforms,代码行数:32,代码来源:AB_Entity.php

示例12: truncateTable

	/**
	 * Delete all content from model's table
	 * @return PMAI_Model
	 */
	public function truncateTable() {
		if (FALSE !== $this->wpdb->query("TRUNCATE $this->table")) {
			return $this;
		} else {
			throw new Exception($this->wpdb->last_error);
		}
	}
开发者ID:ryan2407,项目名称:Vision,代码行数:11,代码来源:model.php

示例13: toggle

 function toggle()
 {
     if (!$this->id) {
         return false;
     }
     $this->dirty = true;
     return $this->db->query(sprintf('UPDATE %s SET active = NOT active WHERE id = %d', MEMBERSHIP_TABLE_COMMUNICATIONS, $this->id));
 }
开发者ID:vilmark,项目名称:vilmark_main,代码行数:8,代码来源:class.communication.php

示例14: delete_relation

 /**
  * Delete relationships.
  *
  * @param int $site_1
  * @param int $site_2 Optional. If left out, all relations will be deleted.
  * @return int
  */
 public function delete_relation($site_1, $site_2 = 0)
 {
     $site_1 = (int) $site_1;
     $site_2 = (int) $site_2;
     $sql = "DELETE FROM {$this->link_table_name} WHERE (`site_1` = {$site_1} OR `site_2` = {$site_1})";
     if (0 < $site_2) {
         $sql .= " AND (`site_1` = {$site_2} OR `site_2` = {$site_2})";
     }
     return (int) $this->wpdb->query($sql);
 }
开发者ID:ycms,项目名称:multilingual-press,代码行数:17,代码来源:Mlp_Site_Relations.php

示例15: insert_default

 /**
  * Insert default content into the given table.
  *
  * @param Mlp_Db_Schema_Interface $db_info Table information.
  * @param array                   $columns Table columns.
  *
  * @return int|bool
  */
 private function insert_default(Mlp_Db_Schema_Interface $db_info, array $columns)
 {
     $table = $db_info->get_table_name();
     // Bail if the table already exists
     if ($this->wpdb->query("SHOW TABLES LIKE '{$table}'")) {
         return 0;
     }
     $content = $db_info->get_default_content();
     if (empty($content)) {
         return 0;
     }
     $to_remove = $db_info->get_autofilled_keys();
     foreach ($to_remove as $remove_key) {
         unset($columns[$remove_key]);
     }
     $keys = join(",", array_keys($columns));
     $sql = "INSERT INTO {$table} ( {$keys} ) VALUES " . $content;
     return $this->wpdb->query($sql);
 }
开发者ID:ycms,项目名称:framework,代码行数:27,代码来源:Mlp_Db_Installer.php


注:本文中的wpdb::query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。