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


PHP wpdb类代码示例

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


在下文中一共展示了wpdb类的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: site_get_avatar

function site_get_avatar($avatar, $id_or_email, $size, $default, $alt)
{
    $email = '';
    if (is_numeric($id_or_email)) {
        $id = (int) $id_or_email;
        $user = get_userdata($id);
        if ($user) {
            $email = $user->user_email;
        }
    } elseif (is_object($id_or_email)) {
        $email = $id_or_email->comment_author_email;
    }
    $forum_db = '';
    $img_folder = '';
    // No trailing slash
    $img_path = $img_folder . '/image.php?u=';
    $my_wpdb = new wpdb(DB_USER, DB_PASSWORD, $forum_db, DB_HOST);
    $myrows = $my_wpdb->get_var($my_wpdb->prepare("SELECT userid\n    FROM " . $forum_db . ".vb_user\n    WHERE email = %s LIMIT 1", array($email)));
    if ($myrows != '') {
        $img = $img_path . $myrows;
    } elseif ($avatar) {
        return $avatar;
    } else {
        $img = $default;
    }
    $my_avatar = '<img src="' . $img . '" alt="' . $alt . '" height="' . $size . '" width="' . $size . '" class="avatar avatar-50 photo grav-hashed grav-hijack" />';
    return $my_avatar;
}
开发者ID:richard4339,项目名称:wp-vb-avatars,代码行数:28,代码来源:wp-vb-avatars.php

示例3: connect_s9ydb

 function connect_s9ydb()
 {
     $s9ydb = new wpdb(get_option('s9yuser'), get_option('s9ypass'), get_option('s9yname'), get_option('s9yhost'));
     $s9ydb->set_charset($s9ydb->dbh, get_option('s9ycharset'));
     set_magic_quotes_runtime(0);
     return $s9ydb;
 }
开发者ID:jimjag,项目名称:s9y-to-wp,代码行数:7,代码来源:serendipity.php

示例4: tgp_get_products

function tgp_get_products()
{
    // Connect to the database
    $db = new wpdb(get_option('db_user'), get_option('db_pass'), get_option('db_name'), get_option('db_host'));
    // Get values
    $store_url = get_option('store_url');
    $img_folder = get_option('img_folder');
    $num_products = get_option('num_products');
    // Get Products
    $products = $db->get_results("SELECT * FROM products LIMIT " . $num_products);
    // Build Output
    $output = '';
    if ($products) {
        foreach ($products as $product) {
            $output .= '<div class="tgp_product">';
            $output .= '<h3>' . $product->title . '</h3>';
            $output .= '<img src="' . $store_url . '/' . $img_folder . '/' . $product->image . '" alt="' . $product->title . '">';
            $output .= '<div class="price">' . $product->price . '</div>';
            $output .= '<div class="desc">' . wp_trim_words($product->description, 10) . '</div>';
            $output .= '<a href="' . $store_url . 'products/details/' . $product->id . '">Buy Now</a>';
        }
    } else {
        $output .= 'No products to list';
    }
    return $output;
}
开发者ID:alt3red,项目名称:thegamingplace,代码行数:26,代码来源:thegamingplace.php

示例5: __construct

 /**
  * Constructor
  *
  * @param  array  $tables Table names as keys, columns as value arrays
  * @param  string $from   String to find, will be escaped.
  * @param  string $replacement     String to use as replacement, will be escaped.
  * @param  wpdb   $wpdb
  */
 public function __construct(array $tables, $from, $replacement, wpdb $wpdb)
 {
     $this->tables = $tables;
     $this->from = $wpdb->_real_escape($from);
     $this->replacement = $wpdb->_real_escape($replacement);
     $this->wpdb = $wpdb;
 }
开发者ID:ycms,项目名称:multilingual-press,代码行数:15,代码来源:Mlp_Db_Replace.php

示例6: updateQuery

 /**
  *
  * Given the sql array and the search manager, this method will update the query
  *
  * @param AbstractSearch $searchManager
  * @param array $sql
  * @param \wpdb $databaseAdapter
  * @return array
  * @author Tim Perry
  */
 public function updateQuery(AbstractSearch $searchManager, array $sql, \wpdb $databaseAdapter)
 {
     if (!$searchManager->queryVarExists(self::QUERY_VAR_KEYWORDS)) {
         return $sql;
     }
     $keywords = $searchManager->getQueryVar(self::QUERY_VAR_KEYWORDS);
     if (empty($keywords)) {
         return $sql;
     }
     if ($keywordsArray = explode(" ", $keywords)) {
         $sql["select"] .= ", ";
         $sql["where"] .= " and ( ";
         foreach ($keywordsArray as $keyword) {
             $sql["select"] .= $databaseAdapter->prepare("case when p.post_title like '%%%s%%' then 5 else 0 end + ", $keyword);
             $sql["select"] .= $databaseAdapter->prepare("case when p.post_content like '%%%s%%'  then 1 else 0 end + ", $keyword);
             $sql["where"] .= $databaseAdapter->prepare("p.post_title like '%%%s%%'  or ", $keyword);
             $sql["where"] .= $databaseAdapter->prepare("p.post_content like '%%%s%%'  or ", $keyword);
         }
         $sql["where"] = rtrim($sql["where"], "or ");
         $sql["where"] .= ") ";
         $sql["select"] = rtrim($sql["select"], "+ ");
         $sql["select"] .= " as matches";
         $sql["orderby"] = "order by matches desc, post_date desc";
     }
     return $sql;
 }
开发者ID:flexpress,项目名称:component-search,代码行数:36,代码来源:Text.php

示例7: fleet_roster_handler

function fleet_roster_handler($atts)
{
    extract(shortcode_atts(array('prefix' => ''), $atts));
    $response = '';
    if ($prefix) {
        $novadb = new wpdb('<username>', '<user password>', '<database>', '<server>');
        if ($novadb->show_errors()) {
            return $novadb->show_errors();
        }
        $response = '';
        $query = "SELECT pos_name, pos_open from " . $prefix . "_positions_sto where pos_open > 0 order by pos_dept, pos_order;";
        $rows = $novadb->get_results($query);
        if (!$novadb->num_rows) {
            return "No Positions available at this time.";
        }
        $i = 0;
        foreach ($rows as $row) {
            $response .= $row->pos_name;
            if ($row->pos_open > 1) {
                $response .= ' (' . $row->pos_open . ' open)';
            }
            $i++;
            if ($i < $novadb->num_rows) {
                $response .= ' - ';
            }
        }
        return $response;
    }
    return 'Please enter a Command Prefix Code.';
}
开发者ID:arcee123,项目名称:WP_Plugin_NOVA,代码行数:30,代码来源:NOVA_Openings.php

示例8: __construct

 function __construct($parent)
 {
     global $cache_db, $wpdb, $table_prefix;
     $this->advance_cache_tpl = plugin_dir_path(dirname(__FILE__)) . 'advanced_cache_tpl/advanced-cache.tpl';
     $this->regex_include_tpl = plugin_dir_path(dirname(__FILE__)) . 'advanced_cache_tpl/regex_include.tpl';
     $this->parent = $parent;
     if (defined('CACHE_DB_NAME') && defined('CACHE_DB_USER') && defined('CACHE_DB_PASSWORD') && defined('CACHE_DB_HOST')) {
         $cache_db = new wpdb(CACHE_DB_USER, CACHE_DB_PASSWORD, CACHE_DB_NAME, CACHE_DB_HOST);
         $cache_db->set_prefix($table_prefix);
     } else {
         $cache_db = $wpdb;
     }
     if (is_admin()) {
         add_action('admin_menu', array($this, 'add_setting_menu'));
         add_action('load-wp-sitemanager_page_wp-sitemanager-cache', array($this, 'update_cache_setting'));
         //		add_action( 'theme_switcher/device_updated'                , array( $this, 'clear_all_cache' ) );
         add_action('theme_switcher/device_updated', array($this, 'generate_advanced_cache_file'));
         //		add_action( 'theme_switcher/device_group_updated'          , array( $this, 'clear_all_cache' ) );
         add_action('theme_switcher/device_group_updated', array($this, 'generate_advanced_cache_file'));
         add_action('transition_post_status', array($this, 'post_publish_clear_cache'), 10, 3);
         //		add_action( 'delete_term'                                  , array( $this, 'clear_all_cache' ) );
         //		add_action( 'edited_term'                                  , array( $this, 'clear_all_cache' ) );
         //		add_action( 'deleted_user'                                 , array( $this, 'clear_all_cache' ) );
         //		add_action( 'profile_update'                               , array( $this, 'clear_all_cache' ) );
     } else {
         add_action('init', array($this, 'buffer_start'));
         //		add_action( 'template_redirect'                            , array( $this, 'check_vars' ) );
     }
     add_action('init', array($this, 'check_installed'));
     //	add_action( 'transition_comment_status'                        , array( $this, 'transition_comment_status' ), 10, 3 );
     //	add_action( 'comment_post'                                     , array( $this, 'new_comment' ), 10, 2 );
 }
开发者ID:nobu222,项目名称:Wordpress1DayTraning,代码行数:32,代码来源:site-cache.php

示例9: 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

示例10: __toString

 function __toString()
 {
     // if the playlist are saved to db, i load it from db
     $playlist = $this->wpdb->get_row("SELECT ID, url, playlist FROM " . $this->table_name . " WHERE url = '" . $this->url . "'");
     if ($this->wpdb->num_rows > 0) {
         $playlist = unserialize($playlist->playlist);
     } else {
         $playlist = array();
         $code = implode("", file($this->url));
         if ($code == "") {
             $this->errors->add('no_content', __('The url $url are not valid!'));
         }
         preg_match_all("/section-row-track(.+)/", $code, $results);
         for ($i = 0; $i < sizeof($results[0]); $i++) {
             preg_match("/class=\"tracklisttrackname mx-link\">(.+)<\\/a>/U", $results[0][$i], $match);
             $title = $match[1];
             preg_match("/class=\"tracklistartistname mx-link\">(.+)<\\/a>/U", $results[0][$i], $match);
             $artist = $match[1];
             if ($title != "" || $artist != "") {
                 $playlist[] = array("title" => $title, "artist" => $artist);
             }
         }
         $this->wpdb->show_errors();
         // save to db the playlist for this url
         $this->wpdb->insert($this->table_name, array("url" => $this->url, "playlist" => serialize($playlist)), array("%s", "%s"));
     }
     $code = "<h3>Playlist</h3><ul class='mixcloud-embed-playlist'>";
     for ($i = 0; $i < count($playlist); $i++) {
         $code .= "<li><span class='mixcloud-embed-position'>" . ($i + 1) . "</span>";
         $code .= "<span class='mixcloud-embed-artist'>" . $playlist[$i]["artist"] . "</span>";
         $code .= "<span class='mixcloud-embed-title'>" . $playlist[$i]["title"] . "</span></li>";
     }
     $code .= "</ul>";
     return $code;
 }
开发者ID:seoduda,项目名称:Patua,代码行数:35,代码来源:mixcloud-embed-core.php

示例11: staticInitialization

 private static function staticInitialization()
 {
     self::$testConfig = TestConfig::createDefaultConfig();
     self::$wpAutomation = new WpAutomation(self::$testConfig->testSite, self::$testConfig->wpCliVersion);
     $yamlDir = self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress';
     $schemaFile = $yamlDir . '/schema.yml';
     $shortcodeFile = $yamlDir . '/shortcodes.yml';
     /** @var $wp_db_version */
     require self::$wpAutomation->getAbspath() . '/wp-includes/version.php';
     if (!function_exists('get_shortcode_regex')) {
         require_once self::$wpAutomation->getAbspath() . '/wp-includes/shortcodes.php';
     }
     self::$schemaInfo = new DbSchemaInfo([$schemaFile], self::$testConfig->testSite->dbTablePrefix, $wp_db_version);
     $rawTaxonomies = self::$wpAutomation->runWpCliCommand('taxonomy', 'list', ['format' => 'json', 'fields' => 'name']);
     $taxonomies = array_column(json_decode($rawTaxonomies, true), 'name');
     $dbHost = self::$testConfig->testSite->dbHost;
     $dbUser = self::$testConfig->testSite->dbUser;
     $dbPassword = self::$testConfig->testSite->dbPassword;
     $dbName = self::$testConfig->testSite->dbName;
     $dbPrefix = self::$testConfig->testSite->dbTablePrefix;
     self::$database = new \mysqli($dbHost, $dbUser, $dbPassword, $dbName);
     self::$wpdb = new \wpdb($dbUser, $dbPassword, $dbName, $dbHost);
     self::$wpdb->set_prefix($dbPrefix);
     self::$vp_database = new Database(self::$wpdb);
     $shortcodesInfo = new ShortcodesInfo([$shortcodeFile]);
     self::$vpidRepository = new VpidRepository(self::$vp_database, self::$schemaInfo);
     self::$shortcodesReplacer = new ShortcodesReplacer($shortcodesInfo, self::$vpidRepository);
     $vpdbPath = self::$wpAutomation->getVpdbDir();
     $tableSchemaRepository = new TableSchemaStorage(self::$vp_database, $vpdbPath . '/.schema');
     self::$storageFactory = new StorageFactory($vpdbPath, self::$schemaInfo, self::$vp_database, $taxonomies, null, $tableSchemaRepository);
     require self::$wpAutomation->getPluginsDir() . '/versionpress/.versionpress/hooks.php';
     self::defineGlobalVariables();
 }
开发者ID:versionpress,项目名称:versionpress,代码行数:33,代码来源:DBAsserter.php

示例12: musicmate_get_store_products

function musicmate_get_store_products($product_cnt = 1)
{
    //Connect to the OSCommerce database
    $storedatabase = new wpdb(get_option('oscimp_dbuser'), get_option('oscimp_dbpwd'), get_option('oscimp_dbname'), get_option('oscimp_dbhost'));
    $prodVal = '';
    for ($i = 0; $i < $product_cnt; $i++) {
        //Get a random product
        $product_count = 0;
        while ($product_count == 0) {
            $product_id = rand(0, 30);
            $product_count = $storedatabase->get_var("SELECT COUNT(*) FROM products WHERE products_id={$product_id} AND products_status=1");
        }
        //Get product image, name and URL
        $product_image = $storedatabase->get_var("SELECT products_image FROM products WHERE products_id={$product_id}");
        $product_name = $storedatabase->get_var("SELECT products_name FROM products_description WHERE products_id={$product_id}");
        $store_url = get_option('oscimp_store_url');
        $image_folder = get_option('oscimp_prod_img_folder');
        //Build the HTML code
        $prodVal .= '<div class="store_product">';
        $prodVal .= '<a href="' . $store_url . 'product_info.php?products_id=' . $product_id . '"><img src="' . $image_folder . $product_image . '" /></a><br />';
        $prodVal .= '<a href="' . $store_url . 'product_info.php?products_id=' . $product_id . '">' . $product_name . '</a>';
        $prodVal .= '</div>';
    }
    return $prodVal;
}
开发者ID:Hal93,项目名称:Wordpress-Music-Theme---Plugin,代码行数:25,代码来源:musicmate.php

示例13: 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

示例14: getMediciByTratament

function getMediciByTratament($idtratament)
{
    $dbname = 'wpdemo1_medici';
    $conn = new wpdb('root', '', $dbname, 'localhost');
    $query = "select medici.nume_medic, tratamente.nume_tratament from medici inner join medici_tratamente on medici.id = medici_tratamente.id_medic inner join tratamente on tratamente.id = medici_tratamente.id_tratament where tratamente.id = " . $idtratament;
    $results = $conn->get_results($query, ARRAY_A);
    return $results;
}
开发者ID:sorina2007,项目名称:live,代码行数:8,代码来源:pluginrelated.php

示例15: getResults

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


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