0

My friend made a xml generator plugin what is owrking fine with WP 3.5, but i need to update for 4.2.2 (cause the security) and the plugins now said 'No database selected', but the informations / datas in wp-config.php file is correct.

The plugin:

<?php

    require_once('../../../wp-config.php'); 

if(file_exists('../../../wp-config.php')){
        echo 'Database is exist';
    }else{
        echo 'n';
    }
$xmlFile = plugin_dir_path( __FILE__ ).'test.xml';


unset($sitemapContent);
$sitemapContent = '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
$sitemapContent .= '<products>'."\n";
$getProductsRes = mysql_query("SELECT * FROM wp_posts WHERE post_type = 'product' AND post_status = 'publish' AND post_parent = '0'");

    if($getProductsRes){

    }else{
        echo mysql_error();
    }

The 'Database is exist' is visible, but the query not executed.

EDIT: Oh, i found the Solution. In WP 3.9 and heighter not supported mysql_query anymore: Link

1
  • Why are you not using $wpdb? Commented Jul 6, 2015 at 8:50

1 Answer 1

1

Try "bootstrapping" WordPress for your custom script first: include '../../../wp-load.php' (you might need to adjust the path for your needs).

Then you can safely use the $wpdb class, such as $wpdb->get_results and other goodies. Don't forget to escape/clean your incoming data, if any. WordPress documentation on $wpdb

PS: always try to use "builtin" functions. The codex above is gold.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.