I have data in one of my websites. I want to print these data in other site. These two are in same server. At present, I have to export MySQL data and import into other then do this code to insert in 2nd domain.
I want to link directly so that I can make data request from 1st website and show in 2nd website.
I know for this to happen, I need to enable bind-address = 127.0.0.1
to ip address of server and I have changed this.
After that in first website, I have granted permission for that table using this command:
GRANT select ON `database-name.tableA`.* TO 'userB'@'localhost';
but I am getting this error:
Failed to connect to MySQL:
Access denied for user 'userA'@'localhost' to database 'database-name.tableA'
The code I am running from website B:
databaseconnect.php
<?php
$con=mysqli_connect("localhost","UserA","passwordA","databaseA");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
main.php
<?
include('/home/website2/public_html/databaseconnect.php');
$res2 = $con->query("SELECT * FROM `website1_tableA` where status='0' order by id asc limit 5");
while($result = $res2->fetch_assoc()){
$cont=$result['content'];
$tit=$result['title'];
echo $cont;
}
?>