Results 1 to 3 of 3

Thread: MySQL to WordPress WPDB conversion?

  1. #1
    Join Date
    Nov 2005
    Posts
    25
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default MySQL to WordPress WPDB conversion?

    Hello,

    I'm trying to convert some old MySQL to work with WordPress WPDB (https://developer.wordpress.org/refe.../wpdb/prepare/). I have taken a stab at it but wanted another eye here as it seems I might not be doing this correct.

    SQL:
    PHP Code:
     <?
              $sql 
    "SELECT wp_acf_values.value FROM wp_acf_values, wp_acf_fields WHERE wp_acf_fields.post_id = '620' AND wp_acf_fields.id = wp_acf_values.field_id ORDER BY wp_acf_fields.order_no";
              
    $result mysql_query($sql) or die('Content was not loaded.');
              
    $counter 0;
              while(
    $post mysql_fetch_array($result)) {

                
    $sqlSecond "SELECT meta_value FROM wp_postmeta WHERE meta_id = '".$post['value']."'";
                
    $result1 mysql_query($sqlSecond) or die('Content was not loaded.');
                while(
    $post1 mysql_fetch_array($result1)) {
                  
    $data[$counter] = $post1['meta_value'];
                  
    $counter++;
                }
              }

              
    // get image
              
    $sql "SELECT meta_value FROM wp_postmeta WHERE post_id = '".$data['1']."' AND meta_key = '_wp_attached_file'";
              
    $result mysql_query($sql) or die('Content was not loaded.');
              
    $counter 0;
              while(
    $post mysql_fetch_array($result)) {
                
    $imgURL $post['meta_value'];
              }
              
    ?>
    WPDB:
    PHP Code:
    <?
              $sql 
    $wpdb->prepare"SELECT wp_acf_values.value FROM wp_acf_values, wp_acf_fields WHERE wp_acf_fields.post_id = '620' AND wp_acf_fields.id = wp_acf_values.field_id ORDER BY wp_acf_fields.order_no" );
              
    $result $wpdb->query $sql ) or die('Content was not loaded.');
              
    $counter 0;
              while(
    $post mysql_fetch_array($result)) {

                
    $sqlSecond $wpdb->prepare"SELECT meta_value FROM wp_postmeta WHERE meta_id = %s"$post['value'] );
                
    $result1 $wpdb->query $sqlSecond ) or die('Content was not loaded.');
                while(
    $post1 mysql_fetch_array($result1)) {
                  
    $data[$counter] = $post1['meta_value'];
                  
    $counter++;
                }
              }

              
    // get image
              
    $sql $wpdb->prepare"SELECT meta_value FROM wp_postmeta WHERE post_id = %s AND meta_key = '_wp_attached_file'"$data['1'] );
              
    $result $wpdb->query $sql ) or die('Content was not loaded.');
              
    $counter 0;
              while(
    $post mysql_fetch_array($result)) {
                
    $imgURL $post['meta_value'];
              }
              
    ?>
    Thanks
    Last edited by wyclef; 07-31-2018 at 03:18 AM.

  2. #2
    Join Date
    Nov 2005
    Posts
    25
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    Seems like mysql_fetch_array won't work. Anyone know how to port that over for WPDB?

  3. #3
    Join Date
    Nov 2005
    Posts
    25
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    Latest effort. Anyone familiar with WPDB?

    PHP Code:
    <?

    global $wpdb;
                
    $sql $wpdb->prepare"SELECT wp_acf_values.value FROM wp_acf_values, wp_acf_fields WHERE wp_acf_fields.post_id = '620' AND wp_acf_fields.id = wp_acf_values.field_id ORDER BY wp_acf_fields.order_no" );
    $result $wpdb->get_results $sql ) or die('Content was not loaded.'); 
    $counter 0;

    foreach (
    $result as $post ) {
         
    $sqlSecond $wpdb->prepare"SELECT meta_value FROM wp_postmeta WHERE meta_id = %s"$post->value );
         
    $result1 $wpdb->get_results $sqlTitle ) or die('Content was not loaded.');
         foreach ( 
    $result1 as $post1 ) {
              
    $data[$counter] = $post1->meta_value;
              
    $counter++;
         }
    }

    // get image
    $sql $wpdb->prepare"SELECT meta_value FROM wp_postmeta WHERE post_id = %s AND meta_key = '_wp_attached_file'"$data['1'] );
    $result $wpdb->get_results $sql ) or die('Content was not loaded.'); 
    $counter 0;
    foreach ( 
    $result as $post ) {
         
    $imgURL $post->meta_value;
         
    $counter++;
    }
    ?>

Similar Threads

  1. Conversion from MS Access to MySQL
    By sovitak in forum MySQL and other databases
    Replies: 1
    Last Post: 09-28-2013, 06:32 PM
  2. Conversion to PDO
    By jdadwilson in forum MySQL and other databases
    Replies: 5
    Last Post: 07-30-2013, 05:02 AM
  3. can CS3 do that swf to flv conversion ?
    By deiilog in forum Flash
    Replies: 2
    Last Post: 06-11-2009, 06:39 AM
  4. Resolved msaccess to mysql db conversion s/w
    By sweetline priya in forum MySQL and other databases
    Replies: 0
    Last Post: 01-12-2009, 08:56 AM
  5. WMA Conversion
    By ocajt714 in forum ASP
    Replies: 1
    Last Post: 09-08-2007, 04:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •