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 ?