I'm using Cryto Plugin and want to get coin price data from plugin db.
For easy practice, I'm trying to get BTC data.
<?php function get_coin_price($coin_symbol) {
global $wpdb;
$coin_price = $wpdb->get_var($wpdb->prepare("SELECT price FROM {$wpdb->prefix}cmc_coins_v2 WHERE symbol = '%s'", $coin_symbol));
return $coin_price;
}?>
And if I want to get BTC price, I use this code.
<?php get_coin_price(BTC); ?>
However I'm getting this error
"Use of undefined constant BTC - assumed 'BTC' (this will throw an Error in a future version of PHP)"
Is there a problem in data type? or maybe am I not using $wpdb->get_var or wpdb->prepare correctly?
$
, and string values need to be encapsulated in quotation marks. Since theBTC
inget_coin_price(BTC)
has neither of these attributes, PHP believes it to be a constant. As this question is regarding PHP syntax rather than WordPress or it's APIs, it may be considered off-topic for our stack