I have a following code on a WordPress theme .php template files:
$star->id = $user_ID ;
$curent_user = get_current_user_id();
$con=mysqli_connect("localhost","username","password","dbname");
$sql = mysqli_query($con,"SELECT * FROM `Fr_star` WHERE `user_id` = ".$curent_user." AND `rate_id` = ".$user_ID."");
The problem is that it stores the username, password, database name in a plain text, which I think is not secure enough.
The question is how can I rewrite this line into the plugin to gain a secure connection to a localhost wp database? How would it look like?
$con=mysqli_connect("localhost","username","password","dbname");
I have tried replacing it with the following line but it didn not worked:
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
In a result I get errors on the pages where the db connections are needed:
Warning: mysqli_connect(): (HY000/1130): Host '127.0.0.1' is not allowed to connect to this MySQL server in .../themes/theme-name/single.php...
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in .../themes/theme-name/single.php...
Regards
==SOLUTION UPDATE==
A use
$con=mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
B and allow database user to connect remotely (enable remote connections)