2017-08-25 87 views
-5

我創建了一個教育網站,學生在這裏註冊了唯一的ID,直到現在沒有問題,但我想從我的數據庫中顯示他的一些信息與特定的唯一id.I已創建網站在wordpress.Please幫助我我如何從數據庫獲取數據到wordpress?

+0

您可以在命令行中使用PHP或MySQL。一旦你嘗試了,給我們看一些代碼,以便我們可以幫助你。 –

+0

我怎麼可以開始吧 –

+0

http://php.net/manual/en/function.mysqli-connect.php –

回答

0
WordPress Database Functions 

    Following are some basic methods 

    /** 
    * insert 
    */ 
    $wpdb->insert($wpdb->posts, array('post_title' => $mytitle)); 

    $wpdb->insert($wpdb->options, array(
      'option_name', 
      'new_option_key', 
      'option_value' => 'New Option Value', 
      'autoload' => 'yes') 
      ); 

    /** 
    * update 
    */ 
    $wpdb->update($wpdb->posts, array('post_title' => $mytitle), 
      array('ID' => $myid) 
      ); 

    $wpdb->update($wpdb->options, 
      array('option_value' => 'New Option Value'), 
      array('option_name' => 'new_option_value') 
      ); 

    /** 
    * get_var 
    */ 
    $post_id = $wpdb->get_var(
      $wpdb->prepare("SELECT post_id FROM 
        $wpdb->postmeta WHERE 
        post_id = %d AND 
        meta_key = 'enclosure' AND 
        meta_value LIKE (%s)", $post_ID, $url . '&') 
      ); 

    $content = $wpdb->get_var(
      $wpdb->prepare("SELECT post_content FROM " . 
        "$wpdb->posts WHERE " . 
        "post_title = %s AND " . 
        "ID = %d", $title, $id) 
     ); 

    /** 
    * query 
    */ 
    $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'"); 

    $wpdb->query("UPDATE $wpdb->posts SET post_title = '$mytitle' WHERE ID = $myid"); 

    /** 
    * query and escape 
    */ 
    $mytitle = $wpdb->escape($mytitle); 
    $myid = absint($myid); 
    $wpdb->query("UPDATE $wpdb->posts SET post_title = '$mytitle' WHERE ID = $myid"); 

    /** 
    * get_results 
    */ 
    $type = $wpdb->get_results("SELECT post_type FROM " . 
       "$wpdb->posts WHERE ID=$id"); 
0
// 1st Method - Declaring $wpdb as global and using it to execute an SQL 
    query statement that returns a PHP object 

    global $wpdb; 
    $results = $wpdb->get_results('SELECT * FROM wp_options WHERE option_id = 1', OBJECT); 

    // 2nd Method - Utilizing the $GLOBALS superglobal. Does not require 
    global keyword (but may not be best practice) 

    $results = $GLOBALS['wpdb']->get_results('SELECT * FROM wp_options WHERE option_id = 1', OBJECT); 
相關問題