Sounds like those two functions could be combined into one function after all that is the primary reason to have a function in order to save a coder some typing.
I personally would do something like the following.
$table = 'tbl_wallet';
$field = 'name of the field';
$searchValue = 1; // Just an placeholder value what would be in the database table;
function fetchColumn ($table, $field, $searchValue) {
$db_options = [
/* important! use actual prepared statements (default: emulate prepared statements) */
PDO::ATTR_EMULATE_PREPARES => false
/* throw exceptions on errors (default: stay silent) */
, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
/* fetch associative arrays (default: mixed arrays) */
, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
];
$pdo= new PDO('mysql:host=' . DATABASE_HOST . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD, $db_options);
$sql = 'SELECT ' . $field . ' FROM ' . $table . ' WHERE user_id =:id LIMIT 1';
$stmt = $pdo->prepare($sql); //
$stmt->execute([ 'id' => $searchValue ]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
$walletResult = fetchColumn($table, $field, $searchValue);
The above could could be streamline immensely and I used PDO instead of mysqli as I haven’t used mysqli in a very long time. Though I would recommend PDO over mysqli as I think it’s easier to use and code. The above code hasn’t been test and there might be some errors, but I was just trying to give the direction I would go.