1

I am trying to get data from database (wordpress website) and displaying it on my front end html page.

My current code:

Jquery:

$(document).ready(function(e) {
    $('#result_submit').click(function() {

     $.ajax({
            url  :ajaxurl,
            type :'POST',
            data: { 'action': 'expense' },
            success: function(data){
                $("#result").html(data);
            }
        });
    }); 
}); 

PHP:

add_action( 'wp_ajax_expense', 'expense_check' );
add_action( 'wp_ajax_nopriv_expense', 'expense_check' );

function expense_check(){
include_once 'dbConnection.php';

$stmt = mysqli_stmt_init($conn);

$income = "select SUM(amount) as incomeNumber FROM wp_myexpenses WHERE entry_type='Income'";
$response = '';

if (! mysqli_stmt_prepare($stmt,$income)) {
     $response = '<h1 style="color:red;padding-top:5%;">SQL Error !!</h1>';
} else {

    echo "going to correct 1";
     mysqli_stmt_execute($stmt);
     echo "going to correct 2";
     $result = mysqli_stmt_get_result($stmt);
     echo "going to correct 3";
     $income_sum = mysqli_fetch_assoc($result); 
     echo "going to correct 4";
     $response = "Total Income is new ".$income_sum['incomeNumber'];
}

echo $response;
}

I successfully tested the same code in my local wordpress site (XAMPP), but when I implemented the same on my original site, its not working. Found mysqli_stmt_get_result is not pulling any info. my current phpinfo() showing that mysqli is enabled.After checking some previous questions and other forums, I understood that mysqlnd has to be enabled to use nd_mysqli .

Currently I am using shared hosting plan of bluehost. As per them mysqlnd is not enabled on shared plan. ALso I dont see any option to enable this online(in php config) I am beginner in php. Is there anyway I can make this work ?

acr
  • 1,674
  • 11
  • 45
  • 77
  • 1
    Note: The object-oriented interface to `mysqli` is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface. Before you get too invested in the procedural style it’s worth switching over. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era when `mysqli` API was introduced and should not be used in new code. – tadman Oct 25 '18 at 16:59
  • 2
    `ALso I dont see any option to enable this online(in php config)` , `dl()` was the only way that I know of but it no longer exists (for most servers) http://php.net/manual/en/function.dl.php That said consider using PDO, it's much better IMO – ArtisticPhoenix Oct 25 '18 at 17:01

0 Answers0