get_results() публичный Метод

Executes a SQL query and returns the entire SQL result.
С версии: 0.71
public get_results ( string $query = null, string $output = OBJECT ) : mixed
$query string SQL query.
$output string Optional. Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants. With one of the first three, return an array of rows indexed from 0 by SQL result row number. Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively. With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded.
Результат mixed Database query results
Пример #1
0
 /**
  * Bind model to database table
  * @param string $tableName
  * @return PMXI_Model
  */
 public function setTable($tableName)
 {
     if (!is_null($this->table)) {
         throw new Exception('Table name cannot be changed once being set.');
     }
     $this->table = $tableName;
     if (!isset(self::$meta_cache[$this->table])) {
         $tableMeta = $this->wpdb->get_results("SHOW COLUMNS FROM {$this->table}", ARRAY_A);
         $primary = array();
         $auto_increment = false;
         foreach ($tableMeta as $colMeta) {
             if ('PRI' == $colMeta['Key']) {
                 $primary[] = $colMeta['Field'];
             }
             if ('auto_increment' == $colMeta['Extra']) {
                 $auto_increment = true;
                 break;
                 // no point to iterate futher since auto_increment means corresponding primary key is simple
             }
         }
         self::$meta_cache[$this->table] = array('primary' => $primary, 'auto_increment' => $auto_increment);
     }
     $this->primary = self::$meta_cache[$this->table]['primary'];
     $this->auto_increment = self::$meta_cache[$this->table]['auto_increment'];
     return $this;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function fetchAll($sql)
 {
     $sql = $this->_prepareSql($sql);
     $result = $this->_db->get_results($sql, ARRAY_A);
     $this->_checkError();
     return $result;
 }
Пример #3
0
 public function load($staff_id)
 {
     $data = $this->wpdb->get_results('
         SELECT c.name AS category_name, s.*
         FROM ' . AB_Category::getTableName() . ' c
         INNER JOIN ' . AB_Service::getTableName() . ' s ON c.id = s.category_id
     ', ARRAY_A);
     if (!$data) {
         $data = array();
     }
     $this->uncategorized_services = AB_Service::query('s')->where('s.category_id', null)->fetchArray();
     $staff_services = AB_StaffService::query('ss')->select('ss.service_id, ss.price, ss.capacity')->where('ss.staff_id', $staff_id)->fetchArray();
     if ($staff_services) {
         foreach ($staff_services as $staff_service) {
             $this->selected[$staff_service['service_id']] = array('price' => $staff_service['price'], 'capacity' => $staff_service['capacity']);
         }
     }
     foreach ($data as $row) {
         if (!isset($this->collection[$row['category_id']])) {
             $abCategory = new AB_Category();
             $abCategory->set('id', $row['category_id']);
             $abCategory->set('name', $row['category_name']);
             $this->collection[$row['category_id']] = $abCategory;
         }
         unset($row['category_name']);
         $abService = new AB_Service($row);
         $this->category_services[$row['category_id']][] = $abService->get('id');
         $this->collection[$row['category_id']]->addService($abService);
     }
 }
 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);
 }
Пример #5
0
 /**
  * Fetch all results for the supplied SQL statement.
  *
  * @param string|\Dewdrop\Db\Select $sql
  * @param array $bind
  * @param string $fetchMode
  * @return array
  */
 public function fetchAll($sql, $bind = array(), $fetchMode = null)
 {
     if (null === $fetchMode) {
         $fetchMode = ARRAY_A;
     }
     $sql = $this->adapter->prepare($sql, $bind);
     $rs = $this->execWpdb($this->wpdb->get_results($sql, $fetchMode));
     return $rs;
 }
 /**
  * @return WPML_TM_ICL_Translations[]
  */
 public function translations()
 {
     if ((bool) $this->related === false) {
         $translation_ids = $this->wpdb->get_results("SELECT translation_id, language_code\n\t\t\t FROM {$this->wpdb->prefix}{$this->table}\n\t\t\t WHERE trid = " . $this->trid());
         foreach ($translation_ids as $row) {
             $this->related[$row->language_code] = $this->tm_records->icl_translations_by_translation_id($row->translation_id);
         }
     }
     return $this->related;
 }
 /**
  * @param string $query
  * @param array $args
  * @param int $elements_num
  *
  * @return array
  */
 public function retrieve($query, $args, $elements_num)
 {
     $result = array();
     $offset = 0;
     while ($offset < $elements_num) {
         $new_query = $query . sprintf(' LIMIT %d OFFSET %s', $this->chunk_size, $offset);
         $new_query = $this->wpdb->prepare($new_query, $args);
         $rowset = $this->wpdb->get_results($new_query, ARRAY_A);
         if (is_array($rowset) && count($rowset)) {
             $result = array_merge($result, $rowset);
         }
         $offset += $this->chunk_size;
     }
     return $result;
 }
Пример #8
0
 function get_active_subscriptions()
 {
     $where = array();
     $orderby = array();
     $where[] = "sub_active = 1";
     $orderby[] = 'id ASC';
     $sql = 'SELECT * FROM ' . MEMBERSHIP_TABLE_SUBSCRIPTIONS;
     if (!empty($where)) {
         $sql .= " WHERE " . implode(' AND ', $where);
     }
     if (!empty($orderby)) {
         $sql .= " ORDER BY " . implode(', ', $orderby);
     }
     return $this->db->get_results($sql);
 }
Пример #9
0
 /**
  * Gets all the rows in a particular range. Used by the list table class for fetching forms on a particular page.
  *
  * @param int $curr_page Current page of the list table.
  * @param int $per_page Number of items to fetch.
  * @return array A numerically indexed array of associative arrays, using column names as keys.
  **/
 public function get_forms($curr_page, $per_page, $post_type = false)
 {
     $start = ($curr_page - 1) * $per_page;
     $where = $post_type ? "post_type = '{$post_type}'" : 1;
     $query = "SELECT * FROM {$this->table_name} WHERE {$where} ORDER BY id DESC LIMIT {$start}, {$per_page}";
     return $this->db->get_results($query, ARRAY_A);
 }
Пример #10
0
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.';
}
Пример #11
0
 /**
  * Log download
  *
  * If you are viewing the right admin page and you use the right GET
  * parameters, this will send the CSV version of the log.
  *
  * @return void
  */
 public function download()
 {
     if (!$this->isDownload()) {
         return;
     }
     // Generate a file name and query based on the group parameters
     $name = $this->downloadName();
     $where = $this->downloadWhere();
     // Add CSV headers
     header('Content-Type: text/csv');
     header('Content-Disposition: attachment; filename="' . $name . '.csv"');
     // Extract the log data from the database and convert it to CSV format
     $results = $this->database->get_results("\n            SELECT *\n            FROM {$this->table}\n            WHERE {$where}\n        ");
     // Print CSV output
     $csv = fopen('php://output', 'w');
     // Extract headings from a database row and add them to the CSV
     fputcsv($csv, $this->headings(end($results)));
     // Extract values from each result and add them to the CSV
     foreach ($results as $result) {
         fputcsv($csv, $this->values($result));
     }
     // Finish writing CSV
     fclose($csv);
     // Prevent the rest of the page appearing in the CSV file
     exit;
 }
 /**
  * Execute the query, with the current variables.
  *
  * @since 3.1.0
  */
 public function query()
 {
     $qv =& $this->query_vars;
     $this->request = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}";
     if (is_array($qv['fields']) || 'all' == $qv['fields']) {
         $this->results = $this->db->get_results($this->request);
     } else {
         $this->results = $this->db->get_col($this->request);
     }
     /**
      * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance.
      *
      * @since 3.2.0
      *
      * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query.
      */
     if (isset($qv['count_total']) && $qv['count_total']) {
         $this->total_users = $this->db->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()'));
     }
     if (!$this->results) {
         return;
     }
     if ('all_with_meta' == $qv['fields']) {
         cache_users($this->results);
         $r = array();
         foreach ($this->results as $userid) {
             $r[$userid] = new WP_User($userid, '', $qv['blog_id']);
         }
         $this->results = $r;
     } elseif ('all' == $qv['fields']) {
         foreach ($this->results as $key => $user) {
             $this->results[$key] = new WP_User($user, '', $qv['blog_id']);
         }
     }
 }
Пример #13
0
 /**
  * @param $source_site_id
  * @param $target_site_id
  * @param $source_content_id
  * @param $target_content_id
  * @param $type
  * @return mixed
  */
 private function get_existing_translation_ids($source_site_id, $target_site_id, $source_content_id, $target_content_id, $type)
 {
     $sql = "\n\t\t\tSELECT DISTINCT `ml_source_blogid`, `ml_source_elementid`\n\t\t\tFROM {$this->link_table}\n\t\t\tWHERE (\n\t\t\t\t   ( `ml_blogid` = %d AND `ml_elementid` = %d )\n\t\t\t\tOR ( `ml_blogid` = %d AND `ml_elementid` = %d )\n\t\t\t\t)\n\t\t\t\tAND `ml_type` = %s";
     $query = $this->wpdb->prepare($sql, $source_site_id, $source_content_id, $target_site_id, $target_content_id, $type);
     $result = $this->wpdb->get_results($query, ARRAY_A);
     return $result;
 }
Пример #14
0
    /**
     * @param int $limit
     * @return mixed
     */
    public function getTopFailedLogins($limit = 10)
    {
        $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 7 day))';
        switch (wfConfig::get('email_summary_interval', 'weekly')) {
            case 'biweekly':
                $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 14 day))';
                break;
            case 'monthly':
                $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 month))';
                break;
        }
        $results = $this->db->get_results($this->db->prepare(<<<SQL
SELECT *,
sum(fail) as fail_count,
max(userID) as is_valid_user
FROM {$this->db->base_prefix}wfLogins
WHERE fail = 1
AND ctime > {$interval}
GROUP BY username
ORDER BY fail_count DESC
LIMIT %d
SQL
, $limit));
        return $results;
    }
Пример #15
0
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;
}
Пример #16
0
 /**
  * @param string      $slug
  * @param string|bool $language
  *
  * @return string
  */
 function get_translated_slug($slug, $language = false)
 {
     if ($slug) {
         $current_language = $this->sitepress->get_current_language();
         $language = $language ? $language : $current_language;
         if (!isset($this->translated_slugs[$slug][$language])) {
             $slugs_translations = $this->wpdb->get_results($this->wpdb->prepare("SELECT t.value, t.language\r\n\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\n\t\t\t\t\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_string_translations t ON t.string_id = s.id\r\n\t\t\t\t\t\t\t\t\t\tWHERE s.name = %s\r\n\t\t\t\t\t\t\t\t\t\t    AND (s.context = %s OR s.context = %s)\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.status = %d\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.value <> ''", 'URL slug: ' . $slug, 'default', 'WordPress', ICL_TM_COMPLETE));
             foreach ($slugs_translations as $translation) {
                 $this->translated_slugs[$slug][$translation->language] = $translation->value;
             }
             // Add empty values for languages not found.
             foreach ($this->sitepress->get_active_languages() as $lang) {
                 if (!isset($this->translated_slugs[$slug][$lang['code']])) {
                     $this->translated_slugs[$slug][$lang['code']] = '';
                 }
             }
         }
         if ($this->translated_slugs[$slug][$language]) {
             $has_translation = true;
             $slug = $this->translated_slugs[$slug][$language];
         } else {
             $has_translation = false;
         }
         if ($has_translation) {
             return $slug;
         }
     } else {
         $has_translation = true;
     }
     return $has_translation ? $slug : $this->st_fallback($slug, $language);
 }
    /**
     * @param int $limit
     * @return mixed
     */
    public function getTopFailedLogins($limit = 10)
    {
        $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 7 day))';
        switch (wfConfig::get('email_summary_interval', 'weekly')) {
            case 'daily':
                $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 day))';
                break;
            case 'monthly':
                $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 month))';
                break;
        }
        $failedLogins = $this->db->get_results($this->db->prepare(<<<SQL
SELECT wfl.*,
sum(wfl.fail) as fail_count
FROM {$this->db->base_prefix}wfLogins wfl
WHERE wfl.fail = 1
AND wfl.ctime > {$interval}
GROUP BY wfl.username
ORDER BY fail_count DESC
LIMIT %d
SQL
, $limit));
        foreach ($failedLogins as &$login) {
            $exists = $this->db->get_var($this->db->prepare(<<<SQL
SELECT !ISNULL(ID) FROM {$this->db->base_prefix}users WHERE user_login = '******' OR user_email = '%s'
SQL
, $login->username, $login->username));
            $login->is_valid_user = $exists;
        }
        return $failedLogins;
    }
 /**
  * Retrieve array of URLs that pingbacked the given URL.
  *
  * Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html
  *
  * @since 1.5.0
  *
  * @param string $url
  * @return array|IXR_Error
  */
 public function pingback_extensions_getPingbacks($url)
 {
     /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     do_action('xmlrpc_call', 'pingback.extensions.getPingbacks');
     $url = $this->escape($url);
     $post_ID = url_to_postid($url);
     if (!$post_ID) {
         // We aren't sure that the resource is available and/or pingback enabled
         return $this->pingback_error(33, __('The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.'));
     }
     $actual_post = get_post($post_ID, ARRAY_A);
     if (!$actual_post) {
         // No such post = resource not found
         return $this->pingback_error(32, __('The specified target URL does not exist.'));
     }
     $comments = $this->db->get_results($this->db->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM {$this->db->comments} WHERE comment_post_ID = %d", $post_ID));
     if (!$comments) {
         return array();
     }
     $pingbacks = array();
     foreach ($comments as $comment) {
         if ('pingback' == $comment->comment_type) {
             $pingbacks[] = $comment->comment_author_url;
         }
     }
     return $pingbacks;
 }
Пример #19
0
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;
}
 public function get_users($search = NULL, $sort = NULL, $order = NULL, $private = false)
 {
     $scdb = new wpdb(DB_USER, DB_PASSWORD, "uolttorg_sc_data", DB_HOST);
     $sql = "SELECT\n          nameUID AS ID,\n          sc1 AS 'SC Handle',\n          sc2 AS 'SC Name',\n          forum AS 'LTT Name',\n          role AS 'Role',\n          shipname AS 'Ships'\n        FROM shipsown\n        JOIN ships ON ship = shipUID\n        JOIN lttname ON name = nameUID";
     if ($search != NULL) {
         $sql .= " WHERE LOWER(CONCAT(nameUID,sc1,sc2,forum,rank,role,shipname)) like lower('%" . $search . "%')";
     }
     if ($sort != NULL) {
         $sql .= " ORDER BY " . $sort;
         if ($order != NULL) {
             $sql .= " " . $order;
         }
     } else {
         $sql .= " ORDER BY sc1 ASC";
     }
     $user_data = $scdb->get_results($sql, ARRAY_A);
     $ranks_list = array("Trainee", "Piolet", "Lieutenant", "Lieutenant First Class", "Commander", "Commander First Class", "Captain", "Admiral", "Commodore", "High Council");
     $ranks_dict = $scdb->get_results("SELECT * FROM points", ARRAY_A);
     $ranks = array();
     foreach ($ranks_dict as $rank) {
         $ranks[$rank['pilotUID']] = array("military" => $ranks_list[$rank['milrank'] - 1], "exploration" => $ranks_list[$rank['exprank']]);
     }
     $sc_users = array();
     foreach ($user_data as $datum) {
         if (isset($sc_users[$datum['ID']])) {
             $sc_users[$datum['ID']]['Ships'][] = $datum["Ships"];
         } else {
             $ship = $datum["Ships"];
             unset($datum["Ships"]);
             $sc_users[$datum['ID']] = $datum;
             $sc_users[$datum['ID']]['Ships'] = array($ship);
         }
         if (isset($ranks[$datum['ID']])) {
             $sc_users[$datum['ID']]['Rank'] = $ranks[$datum['ID']];
         } else {
             $sc_users[$datum['ID']]['Rank']['military'] = "Recruit";
             // default if not already set
         }
         if (!$private) {
             unset($sc_users[$datum['ID']]['Role']);
             unset($sc_users[$datum['ID']]['Ships']);
             unset($sc_users[$datum['ID']]['SC Handle']);
         }
     }
     return $sc_users;
 }
Пример #21
0
 public function get_relationships()
 {
     if ($this->ID == 0) {
         return false;
     }
     $result = $this->_wpdb->get_results(sprintf('SELECT * FROM %s WHERE user_id = %d AND sub_id != 0', MEMBERSHIP_TABLE_RELATIONS, $this->ID));
     return !empty($result) ? $result : false;
 }
 /**
  * @return WPML_TM_ICL_Translations[]
  */
 public function translations()
 {
     if ((bool) $this->related === false) {
         $trid = $this->trid();
         $found = false;
         $cache = new WPML_WP_Cache('WPML_TM_ICL_Translations::translations');
         $this->related = $cache->get($trid, $found);
         if (!$found) {
             $translation_ids = $this->wpdb->get_results("SELECT translation_id, language_code\n\t\t\t\t    FROM {$this->wpdb->prefix}{$this->table}\n\t\t\t\t    WHERE trid = " . $trid);
             foreach ($translation_ids as $row) {
                 $this->related[$row->language_code] = $this->tm_records->icl_translations_by_translation_id($row->translation_id);
             }
             $cache->set($trid, $this->related);
         }
     }
     return $this->related;
 }
Пример #23
0
 /**
  * @param $criteria
  * @param $cast
  * @return array|null|object
  */
 public function findBy($criteria, $cast = false)
 {
     $objectArray = array();
     $returnType = $cast ? OBJECT : ARRAY_A;
     $criteria = $this->parseCriteria($criteria);
     if (class_exists($this->modelClass)) {
         $model = new $this->modelClass();
         $tableName = $this->wpdb->prefix . $model::TABLE_NAME;
         $res = $this->wpdb->get_results($this->wpdb->prepare("\n                SELECT *\n                FROM {$tableName}\n                WHERE {$criteria["where"]}\n                {$criteria["order"]}\n            ", $criteria["values"]), $returnType);
         if ($cast) {
             foreach ($res as $row) {
                 $objectArray[] = $this->cast($this->modelClass, $row);
             }
         }
         return $cast ? $objectArray : $res;
     }
     return null;
 }
Пример #24
0
function client_email_exists($client_email)
{
    $con = new wpdb(MYSQL_ROUTING_USER, MYSQL_ROUTING_PASSWORD, MYSQL_ROUTING_DB, MYSQL_ROUTING_HOST);
    $results = $con->get_results("select * from `client` where `email` = '{$client_email}'");
    if ($results) {
        return true;
    }
    return false;
}
 public function load($staff_id)
 {
     $data = $this->wpdb->get_results('
         SELECT c.name AS category_name, s.*
         FROM ab_category c
         INNER JOIN ab_service s ON c.id = s.category_id
     ', ARRAY_A);
     if (!$data) {
         $data = array();
     }
     $uncategorized_services = $this->wpdb->get_results('SELECT * FROM ab_service WHERE category_id IS NULL');
     foreach ($uncategorized_services as $uncategorized_service) {
         $abService = new AB_Service();
         $abService->setData($uncategorized_service);
         $this->uncategorized_services[] = $abService;
     }
     $rows = $this->wpdb->get_results($this->wpdb->prepare('
         SELECT s.service_id, s.price, s.capacity
         FROM ab_staff_service s
         WHERE s.staff_id = %d
     ', $staff_id));
     if ($rows) {
         foreach ($rows as $row) {
             $this->selected[$row->service_id] = array('price' => $row->price, 'capacity' => $row->capacity);
         }
     }
     foreach ($data as $row) {
         if (!isset($this->collection[$row['category_id']])) {
             $abCategory = new AB_Category();
             $abCategory->set('id', $row['category_id']);
             $abCategory->set('name', $row['category_name']);
             $this->collection[$row['category_id']] = $abCategory;
         }
         unset($row['category_name']);
         $abService = new AB_Service();
         $abService->setData($row);
         $this->category_services[$row['category_id']][] = $abService->get('id');
         $this->collection[$row['category_id']]->addService($abService);
     }
 }
Пример #26
0
 /**
  * Fetches rows from database.
  *
  * @since 1.0.0
  *
  * @access public
  * @param string $table The table name.
  * @param array|string $columns The array of columns to select.
  * @param array $criteria The array of conditions.
  * @return array The array of fetched rows.
  */
 public function grabFromDatabase($table, $columns, $criteria = array())
 {
     $query = $this->_prepareQuery($table, $columns, $criteria);
     $this->debugSection('Query', $query);
     $suppress_errors = $this->_wpdb->suppress_errors(true);
     $results = $this->_wpdb->get_results($query);
     $this->_wpdb->suppress_errors($suppress_errors);
     if (!empty($this->_wpdb->last_error)) {
         $this->fail('Database error: ' . $this->_wpdb->last_error);
         return;
     }
     return $results;
 }
Пример #27
0
 /**
  * Test the update quiz functionality is working
  * correctly also checks to see if the filter
  * 'wpsqt_pre_save_quiz_details' is called along
  * the way.
  * 
  * @since 2.0
  */
 public function testQuizUpdate()
 {
     $this->dummyQuizId = Wpsqt_System::insertItemDetails($this->dummyQuizDetails, 'quiz');
     $updateDetails = $this->dummyQuizDetails;
     $updateDetails['id'] = $this->dummyQuizId;
     $updateDetails['name'] = "PHPUnit test updated";
     Wpsqt_System::updateItemDetails($updateDetails, "quiz");
     $results = $this->db->get_results($this->db->prepare("SELECT * FROM `" . WPSQT_TABLE_QUIZ_SURVEYS . "` WHERE id = %d", array($this->dummyQuizId)), ARRAY_A);
     $this->assertTrue(is_array($results), "The results from the SQL aren't an array");
     $this->assertEquals(sizeof($results), 1, "There are more results than there should be.");
     $this->assertEquals($updateDetails['name'], $results[0]['name'], "The name hasn't changed. Expecting");
     $this->assertTrue($this->filterCalled, "Seems the 'wpsqt_pre_save_quiz_details' filter.");
 }
 /**
  * Return the existing translation IDs according to the given parameters.
  *
  * @param int    $source_site_id    Source blog ID.
  * @param int    $target_site_id    Target blog ID.
  * @param int    $source_content_id Source post ID or term taxonomy ID.
  * @param int    $target_content_id Target post ID or term taxonomy ID.
  * @param string $type              Content type.
  *
  * @return array
  */
 public function get_existing_translation_ids($source_site_id, $target_site_id, $source_content_id, $target_content_id, $type)
 {
     $sql = "\nSELECT DISTINCT ml_source_blogid, ml_source_elementid\nFROM {$this->link_table}\nWHERE (\n\t\t( ml_blogid = %d AND ml_elementid = %d )\n\t\tOR ( ml_blogid = %d AND ml_elementid = %d )\n\t)\n\tAND ml_type = %s";
     $query = $this->wpdb->prepare($sql, $source_site_id, $source_content_id, $target_site_id, $target_content_id, $type);
     $result = $this->wpdb->get_results($query, ARRAY_A);
     if (!$result) {
         return array();
     }
     foreach ($result as $key => $data) {
         $result[$key] = array_map('intval', $data);
     }
     return $result;
 }
Пример #29
0
 /**
  * @param string $slug
  * @param string $post_type
  * @param string|bool $language
  *
  * @return string
  */
 function get_translated_slug($slug, $post_type, $language = false)
 {
     if ($post_type) {
         $language = $language ? $language : $this->sitepress->get_current_language();
         if (!isset($this->translated_slugs[$post_type][$language])) {
             $slug_original = $this->wpdb->get_row($this->wpdb->prepare("SELECT s.value, s.language\r\r\n\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\r\n\t\t\t\t\t\t\t\t\t\tWHERE s.name = %s\r\r\n\t\t\t\t\t\t\t\t\t\t    AND (s.context = %s OR s.context = %s)", 'URL slug: ' . $post_type, 'default', 'WordPress'));
             if ((bool) $slug_original === true) {
                 $this->translated_slugs[$post_type][$slug_original->language] = $slug_original->value;
                 $slugs_translations = $this->wpdb->get_results($this->wpdb->prepare("SELECT t.value, t.language\r\r\n\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\r\n\t\t\t\t\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_string_translations t ON t.string_id = s.id\r\r\n\t\t\t\t\t\t\t\t\t\tWHERE s.name = %s\r\r\n\t\t\t\t\t\t\t\t\t\t    AND (s.context = %s OR s.context = %s)\r\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.status = %d\r\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.value <> ''", 'URL slug: ' . $post_type, 'default', 'WordPress', ICL_TM_COMPLETE));
                 foreach ($slugs_translations as $translation) {
                     $this->translated_slugs[$post_type][$translation->language] = $translation->value;
                 }
                 foreach ($this->sitepress->get_active_languages() as $lang) {
                     if (!isset($this->translated_slugs[$post_type][$lang['code']])) {
                         $this->translated_slugs[$post_type][$lang['code']] = $slug;
                     }
                 }
             }
         }
         $slug = !empty($this->translated_slugs[$post_type][$language]) ? $this->translated_slugs[$post_type][$language] : $slug;
     }
     return $slug;
 }
Пример #30
0
 /**
  * @param $ids string|array
  *
  * @return mixed
  */
 public function find_by_id($ids)
 {
     if (is_array($ids)) {
         // create comma-separated string
         $ids = implode(',', $ids);
     }
     // escape string for usage in IN clause
     $ids = esc_sql($ids);
     $sql = sprintf("SELECT * FROM `%s` WHERE ID IN (%s)", $this->table_name, $ids);
     // return single row if only one id is given
     if (substr_count($ids, ',') === 0) {
         return $this->db->get_row($sql);
     }
     return $this->db->get_results($sql);
 }