I create three virtual Machine running Ubuntu 14.04 in VMWare Player. First VM - Client who will access the web pages. Second VM - Apache Web Server and PHP Server Third VM - MYSQL Database Server.
I was able to create user in third vm , providing it all the privileges . Using two commands Create User using this command.
mysql> CREATE USER 'user'@'%' IDENTIFIED BY '123456';
mysql> GRANT ALL PRIVILEGES ON project_2.* TO 'user'@'%' WITH GRANT OPTION;
Checking it is working
mysql -u root -h your.mysql.server.address –p
I have reach to this step without any error and is able to access database and perform operations on it.
Now i am looking to write a php script to access the database in web browser but unable to do it. Php script is kept in Second VM.
My code For php script is
<?php
$conn = mysql_connect('database','user','123456');
if(!$conn){
echo "bye";
}
else{
echo "hi";
}
mysql_select_db('project_2',$conn);
$query="select * from test";
$result=mysql_query($query);
echo "<table border='1'>";
echo "<tr>";
echo "<th>Name</th>";
echo "</tr>";
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>",$row['name'],"</td>";
echo "</tr>";
}
?>