Connecting Tech Pros Worldwide Forums | Help | Site Map

How to retrieve data from database in different machine?

Newbie
 
Join Date: Apr 2007
Posts: 7
#1: Apr 8 '07
I am currently building a database with 3 tables using Mysql in solaris 9. I have work out my API in windows using dreamweaver. I would like to try linking the API and database by using php and apache server? anyone who can help me solve thi problem?

ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#2: Apr 8 '07

re: How to retrieve data from database in different machine?


Quote:

Originally Posted by yoyoz

I am currently building a database with 3 tables using Mysql in solaris 9. I have work out my API in windows using dreamweaver. I would like to try linking the API and database by using php and apache server? anyone who can help me solve thi problem?

So your MySQL Database i running under Solaris and your Apache Web Server is Running Under Windows.
If you Need to Call for Database from your API use the IP Address and MySQL Port of that Solaris Machine.
Newbie
 
Join Date: Apr 2007
Posts: 7
#3: Apr 8 '07

re: How to retrieve data from database in different machine?


Quote:

Originally Posted by ajaxrand

So your MySQL Database i running under Solaris and your Apache Web Server is Running Under Windows.
If you Need to Call for Database from your API use the IP Address and MySQL Port of that Solaris Machine.

Yes. you are right. actually i am new to php, can you just guide me what script should i use? may be can you just give me a sample script? thanks a lot...
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#4: Apr 9 '07

re: How to retrieve data from database in different machine?


There are lots of sample scripts here for the beginners.
http://www.w3schools.com/php/php_mysql_intro.asp
Newbie
 
Join Date: Apr 2007
Posts: 7
#5: Apr 9 '07

re: How to retrieve data from database in different machine?


Quote:

Originally Posted by ajaxrand

There are lots of sample scripts here for the beginners.
http://www.w3schools.com/php/php_mysql_intro.asp

I had found some php script regarding the connection, but it still can't work.
The error message is:

Warning: mysql_connect(): Can't connect to MySQL server on 'Solaris IP add' (10054) in c:\program files\easyphp1-7\www\view-taxo-solaris.php on line 11
Problem connecting to DataBaseCan't connect to MySQL server on 'Solaris IP add' (10054)

Below is my php script:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SEA Fruit flies Database System<</title>
</head>
<body bgcolor=#ffffff>
<h2>Data from taxo</h2>

<?
$MyConn=mysql_connect("Solaris IP add: port","root","");
if (!$MyConn) {
die ("Problem connecting to DataBase".mysql_error());
}
echo 'Connected successfully';
mysql_close($MyConn);
$query = "select * from taxo order by genus, species";
$result = mysql_db_query("seaff_2007", $query);

if ($result) {
echo "Found these entries in the database:<br><p></p>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#99CC00>Subfamily</td>
<td align=center bgcolor=#99CC00>Tribe</td>
<td align=center bgcolor=#99CC00>Subgenus</td>
<td align=center bgcolor=#99CC00>Genus</td>
<td align=center bgcolor=#99CC00>Species</td>
<td align=center bgcolor=#99CC00>Distribution</td>
</tr>";

while ($r = mysql_fetch_array($result)) {

$subf = $r["subfamily"];
$tribe = $r["tribe"];
$subg = $r["subgenus"];
$genus = $r["genus"];
$spe = $r["species"];
$distri = $r["distribution"];


echo "<tr>
<td>$subf</td>
<td>$tribe</td>
<td>$subg</td>
<td>$genus</td>
<td>$spe</td>
<td>$distri</td>
</tr>";
}
echo "</table>";

} else {
echo "No data.";
}

mysql_free_result($result);
?>

</body>
</html>

Should i put all my php file in the Solaris machine as well? Or i need to change any configuration in the Windows or Solaris machine? Just to stress that i would like to call out the data from solaris through my windows machine.
Thanks.
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#6: Apr 10 '07

re: How to retrieve data from database in different machine?


If didn't change the port number for my sql, the default is 3306.

first try to establish the connection then try to fetch the database values.

[PHP]<?php
$dbcnx = mysql_connect("127.0.0.1:3306","root","dba");
if ($dbcnx)
{
echo 'Success';
}
else
{
echo ' Unable' ;
}
?>[/PHP]

try like this also. with out the port.
[PHP]$dbcnx = mysql_connect("127.0.0.1","root","dba");[/PHP]
make sure to use the ip,username.pwd of your solaris node.
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#7: Apr 10 '07

re: How to retrieve data from database in different machine?


Quote:

Originally Posted by yoyoz

I had found some php script regarding the connection, but it still can't work.
The error message is:

Warning: mysql_connect(): Can't connect to MySQL server on 'Solaris IP add' (10054) in c:\program files\easyphp1-7\www\view-taxo-solaris.php on line 11
Problem connecting to DataBaseCan't connect to MySQL server on 'Solaris IP add' (10054)

Below is my php script:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SEA Fruit flies Database System<</title>
</head>
<body bgcolor=#ffffff>
<h2>Data from taxo</h2>

<?
$MyConn=mysql_connect("Solaris IP add: port","root","");
if (!$MyConn) {
die ("Problem connecting to DataBase".mysql_error());
}
echo 'Connected successfully';
mysql_close($MyConn);
$query = "select * from taxo order by genus, species";
$result = mysql_db_query("seaff_2007", $query);

if ($result) {
echo "Found these entries in the database:<br><p></p>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#99CC00>Subfamily</td>
<td align=center bgcolor=#99CC00>Tribe</td>
<td align=center bgcolor=#99CC00>Subgenus</td>
<td align=center bgcolor=#99CC00>Genus</td>
<td align=center bgcolor=#99CC00>Species</td>
<td align=center bgcolor=#99CC00>Distribution</td>
</tr>";

while ($r = mysql_fetch_array($result)) {

$subf = $r["subfamily"];
$tribe = $r["tribe"];
$subg = $r["subgenus"];
$genus = $r["genus"];
$spe = $r["species"];
$distri = $r["distribution"];


echo "<tr>
<td>$subf</td>
<td>$tribe</td>
<td>$subg</td>
<td>$genus</td>
<td>$spe</td>
<td>$distri</td>
</tr>";
}
echo "</table>";

} else {
echo "No data.";
}

mysql_free_result($result);
?>

</body>
</html>

Should i put all my php file in the Solaris machine as well? Or i need to change any configuration in the Windows or Solaris machine? Just to stress that i would like to call out the data from solaris through my windows machine.
Thanks.

Please use [PHP] [ /PHP] Tags around your Scripts.Read the posting guidelines.
Newbie
 
Join Date: Apr 2007
Posts: 7
#8: Apr 10 '07

re: How to retrieve data from database in different machine?


Quote:

Originally Posted by ajaxrand

Please use [PHP] [ /PHP] Tags around your Scripts.Read the posting guidelines.

i have tried to establish the connection with the IP add of the Solaris machine bt it still cannot work.
what if i have accidentally changed the port number in Solaris? or may be someone else did?
can i know where i can look for the setting? thanks you so much.
Reply